Skip to content

Instantly share code, notes, and snippets.

@badri
Created June 21, 2016 09:03
Show Gist options
  • Save badri/414e5ab83f25c0b7464c2467aa08a7fd to your computer and use it in GitHub Desktop.
Save badri/414e5ab83f25c0b7464c2467aa08a7fd to your computer and use it in GitHub Desktop.
Pika test
import pika
import json
class Connection(object):
"""singleton pika connection"""
_connection = None
@staticmethod
def get_shared_connection():
if not Connection._connection:
parameters = pika.URLParameters('amqp://lakshmi:[email protected]:5672/%2F')
Connection._connection = pika.BlockingConnection(parameters)
return Connection._connection
for i in range(3):
connection = Connection.get_shared_connection()
channel = connection.channel()
queue = 'app-name-drupal7-' + str(i)
channel.queue_declare(queue=queue)
for method_frame, properties, body in channel.consume(queue = queue):
payload = json.loads(body)
print json.dumps(payload)
channel.basic_ack(method_frame.delivery_tag)
if method_frame.delivery_tag == 1:
break
channel.queue_delete(queue=queue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment