SQS消息接收器中缺少MessageAttributes属性

时间:2019-07-23 22:55:31

标签: amazon-web-services amazon-sqs

我所看到的就是这种类型的数据:

phi=(1+math.sqrt(5))/2

当我进行此调用以从队列中读取时:

    {
      MessageId: 'c604c772-8468-4cd2-8f3e-9b430ed52d92',
      ReceiptHandle: 'AQEBHyPYuNqFztvy9QNOHeLQg==',
      MD5OfBody: '096c6509c8628bde267adde2b105f4e4',
      Body: 'foobar'
    }

但是我在将消息放入队列时添加了MessageAttributes:

sqs.sendMessageBatch({QueueUrl,Entries:v},cb);

条目是一个数组:

const conf = {
  QueueUrl: 'https://sqs.us-west-2.amazonaws.com/920371/logging-q',
  WaitTimeSeconds: 19,  // max is 20 (off by one errors avoided!)
  MaxNumberOfMessages: 9  // max is 10 (off by one errors avoided!)
};

sqs.receiveMessage(conf, cb);

有人知道为什么当我从队列中读取消息时,MessageAttributes却没有出现吗?

1 个答案:

答案 0 :(得分:3)

在您的receiveMessage conf中,您需要包括MessageAttributeNames并为其提供属性名称列表或All。看来您使用的是JavaScript,所以您想看看receiveMessage https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#receiveMessage-property

的Javascript SDK文档