Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boto SQS: delete RawMessage

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

like image 602
Granit Avatar asked Nov 26 '25 19:11

Granit


1 Answers

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.

like image 93
garnaat Avatar answered Nov 28 '25 13:11

garnaat