Skip to content

ReceiveMessage does not filter out MessageAttribute #97

@zsiddique

Description

@zsiddique

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html
So the AWS API is a little vague on this but testing shows that when ReceiveMessage is called with no MessageAttributeName defined ReceiveMessage returns messages with no MessageAttribute. But elaticmq will return MessageAttribute regardless what is asked in MessageAttributeName.
This caused a problem for us as we are using elasticmq to test our usage of SQS and we had a bug in which we neglected to request an MessageAttribute but would work in testing but failed once we got to integration testing with real SQS.
Example using boto. First with Elasticmq

In [6]: c.send_message(MessageBody="ABody", MessageAttributes={'version': {  'StringValue': '1', 'DataType': 'String'}})
Out[6]:
{u'MD5OfMessageAttributes': '75cba0c5eb8ce78d6a41a35f99bfd7a8',
 u'MD5OfMessageBody': '3aff89437ced3559d5e62a20eeb3ea52',
 u'MessageId': '18791ce9-b66e-4ed5-ad31-e93064fcd673',
 'ResponseMetadata': {'HTTPHeaders': {'content-length': '579',
   'content-type': 'text/plain; charset=UTF-8',
   'date': 'Tue, 07 Mar 2017 00:30:02 GMT',
   'server': 'akka-http/2.3.15'},
  'HTTPStatusCode': 200,
  'RequestId': '00000000-0000-0000-0000-000000000000',
  'RetryAttempts': 0}}

In [7]: m = c.receive_messages()

In [8]: m[0].message_attributes
Out[8]: {'version': {u'DataType': 'String', u'StringValue': '1'}}

With AWS SQS:

In [5]: c.send_message(MessageBody="ABody", MessageAttributes={'version': {  'StringValue': '1', 'DataType': 'String'}})
Out[5]:
{u'MD5OfMessageAttributes': '75cba0c5eb8ce78d6a41a3xxxxx',
 u'MD5OfMessageBody': '3aff89437ced3559d5e62a20xxxxxx',
 u'MessageId': '283c0711-6abd-42a5-b4d4-6b95c8cef099',
 'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive',
   'content-length': '459',
   'content-type': 'text/xml',
   'date': 'Tue, 07 Mar 2017 01:27:43 GMT',
   'server': 'Server',
   'x-amzn-requestid': 'bface69a-2ca7-5b7f-bb32-xxxxxxx'},
  'HTTPStatusCode': 200,
  'RequestId': 'bface69a-2ca7-5b7f-bb32-xxxxxxxx',
  'RetryAttempts': 0}}

In [6]: m = c.receive_messages()
In [7]: m[0].message_attributes

In [8]:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions