Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法使用节点js向AWS SQS发送messageAttributes_Node.js_Amazon Web Services_Amazon Sqs - Fatal编程技术网

Node.js 无法使用节点js向AWS SQS发送messageAttributes

Node.js 无法使用节点js向AWS SQS发送messageAttributes,node.js,amazon-web-services,amazon-sqs,Node.js,Amazon Web Services,Amazon Sqs,我试图使用节点Js向AWS SQS发送消息。为此,我安装了npm包AWS sdk。我需要发送一个json数组作为消息属性,它的格式是 {"Header": {"OrganizationName": "testOrg","TYPE": "TestMsg", "UserName": "TestUser"}} 但是这种格式不允许我发送消息 var params = { DelaySeconds: 10, MessageAttributes: { "Ti

我试图使用节点Js向AWS SQS发送消息。为此,我安装了npm包AWS sdk。我需要发送一个json数组作为消息属性,它的格式是

{"Header": {"OrganizationName": "testOrg","TYPE": "TestMsg", "UserName": "TestUser"}}
但是这种格式不允许我发送消息

    var params = {
      DelaySeconds: 10,
      MessageAttributes: {
        "Title": {
          DataType: "String",
          StringValue: "The Whistler"
        },
        "Author": {
          DataType: "String",
          StringValue: "John Grisham"
        },
        "WeeksOn": {
          DataType: "Number",
          StringValue: "6"
        }
      },
      MessageBody: "Information about current NY Times fiction bestseller for week of 12/11/2016.",
      // MessageDeduplicationId: "TheWhistler",  // Required for FIFO queues
      // MessageId: "Group1",  // Required for FIFO queues
      QueueUrl: "SQS_QUEUE_URL"
    };
sqs.sendMessage(params, function(err, data) {

  if (err) {

   console.log("Error", err);

  } else {

    console.log("Success", data.MessageId);

  }

如何在Message Attribute中发送JSON数组?

该格式正确,我可以确认我已使用用于NodeJS的SDK成功发送了使用该格式的messageAttributes

你可能会发现问题在接受方。除非在ReceiveMessageRequest的MessageAttributeName中指定要接收的属性,否则接收方不会获取属性。执行此操作的特定语法因语言SDK而异,在Java和Swift SDK上,您可以提供“All”作为attributeName以获取所有属性。对于我的Swift SDK,我用
receiveMsgRequest.messageAttributeNames=[“All”]
指定了这个属性,然后我开始成功地接收属性


另外,不要将接收方的
message.attributes
message.messageAttributes
混淆。前者用于系统属性。后者是您想要的。

您会遇到什么错误?