How to retrieve attributes of message written to a SQS queue using Boto?

26 views
Skip to first unread message

Sreedath Namangalam

unread,
May 5, 2015, 11:13:17 AM5/5/15
to boto-...@googlegroups.com

I have the following code snippet.

conn = boto.sqs.connect_to_region(region)
q = conn.lookup('myqueue')
m = Message()
m.set_body('My Message')
data = {"UserID": {"data_type": "Number","string_value": "11111"}}
m.message_attributes = user_data
q.write(m)

Using this, I have successfully written the attributes I wanted with the message. Now, I wanted to retrieve it. I have tried

msg.message_attributes

But I have got an empty dictionary only.

Is this the way to retrieve it? Or am I wrong somewhere?

Sreedath Namangalam

unread,
May 6, 2015, 3:19:42 AM5/6/15
to boto-...@googlegroups.com

I have got the answer to my question.

For this you must have retrieved the message like this

attributes = ['UserID']
msgs = q.get_messages(message_attributes=attributes)

Will get msgs as a list. And let msg be msgs[0] Then the message attribute can be retrieved by the following code.

msg.message_attributes['UserID']['string_value']
Reply all
Reply to author
Forward
0 new messages