Skip to content

Instantly share code, notes, and snippets.

@atlantis0
Created March 31, 2015 07:05
Show Gist options
  • Save atlantis0/2d9d5fae972611b0a25e to your computer and use it in GitHub Desktop.
Save atlantis0/2d9d5fae972611b0a25e to your computer and use it in GitHub Desktop.
SQS Demo
import boto
import ast
from boto.sqs.message import RawMessage
from boto.sqs.connection import SQSConnection
sqs_conn = SQSConnection('', '')
queue = sqs_conn.create_queue('SirackQueueTest')
queue.set_message_class(boto.sqs.message.RawMessage)
# var1 = {'First Name':'Sirack', 'Last Name':'Hailu', "Today":"Now"} #first message
# #writing body one
# raw_messaga_one = RawMessage()
# raw_messaga_one.set_body(var1)
# # do the actaul writting
# queue.write(raw_messaga_one)
# body2 = {'First Name':'Beyene', 'Last Name':'Gember'} #second message
# #writting body two
# raw_messaga_two = RawMessage()
# raw_messaga_two.set_body(body2)
# queue.write(raw_messaga_two)
tasks = queue.get_messages(num_messages=3, visibility_timeout=30)
print len(tasks)
for task in tasks:
message = ast.literal_eval(task.get_body())
print message
sqs_conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment