I am using python boto 2.8 and i couldn't delete the messages. Here is 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?
Could anyone here guide me how to delete this? Sometimes i get 1 message, sometimes 3. And i don't want to save the same bounce email each pull, that's why i need to delete it once i save them.
Thanks
Each of the objects in the returned result set is a RawMessage object which has a delete method. So, if you coded your loop a bit 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 message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With