Boto SQS: Remove RawMessage
I am using python boto 2.8 and I was unable to delete messages. Here's my test code:
conn = boto.sqs.connect_to_region("us-east-1",
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY)
q = conn.get_queue("sqs_bounces")
q.set_message_class(RawMessage) //need this to be able to get message as json
results = q.get_messages(num_messages=10,visibility_timeout=30,wait_time_seconds=10)
for rs in results:
str = rs.get_body()
print str
result = json.loads(str)
rs = json.loads(result["Message"])
print rs["notificationType"]
#get the email and save it as bounced
// Do saving.....
#Delete message
//How do i delete the current message?
Can anyone here advise me on how to remove this? Sometimes I get 1 message, sometimes 3. And I don't want to keep the same bounce email every time, so I need to delete it as soon as I save them.
thank
+3
source to share
1 answer
Each of the objects in the returned result set is a RawMessage object that has a delete
. So, if you coded your loop to look a little more like this:
for msg in results:
body = msg.get_body()
body = json.loads(body)
message_body = json.loads(body['Message'])
...
msg.delete()
You should be able to delete the post.
+3
source to share