user11810894
user11810894

Reputation:

Missing MessageAttributes property in SQS message receiver

All I see is this type of data:

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

when I make this call to read from the queue:

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);

but I addeded MessageAttributes when put the messages on the queue:

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

Entries is an array of:

{
    Id: uuid.v4(),
    MessageBody: 'foobar',
    MessageAttributes: {

      logStream: {
        StringValue: LOG_STREAM,
        DataType: 'String'
      },

      logGroup: {
        StringValue: LOG_GROUP,
        DataType: 'String'
      }
    }
  }

anybody know why the MessageAttributes aren't showing up when I read from the queue, even they presumably are being pushed to the queue?

Upvotes: 2

Views: 3163

Answers (1)

Ngenator
Ngenator

Reputation: 11259

In your receiveMessage conf you need to include MessageAttributeNames and either give it a list of attribute names or All. Looks like you're using javascript so you'll want to take a look at the Javascript SDK docs for receiveMessage https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#receiveMessage-property

Upvotes: 6

Related Questions