Skip to content

Instantly share code, notes, and snippets.

@dzderic
Created June 8, 2012 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzderic/2892636 to your computer and use it in GitHub Desktop.
Save dzderic/2892636 to your computer and use it in GitHub Desktop.
import time
import pika
from pika.adapters import SelectConnection
N = 10000
channel = None
count = 0
start = None
def on_connected(connected):
connection.channel(on_channel_open)
def on_channel_open(new_channel):
global channel
channel = new_channel
channel.queue_declare(queue='some_durable_queue', durable=True, callback=on_queue_declared)
def on_queue_declared(frame):
global start
start = time.time()
channel.basic_consume(handle_delivery, queue='some_non_durable_queue', no_ack=True)
def handle_delivery(channel, method, header, body):
global count
count += 1
if count % N == 0:
finish_up()
count = 0
def finish_up():
global start
end = time.time()
total = end - start
start = time.time()
print "Took %f seconds" % (total),
print "%f messages/sec" % (N / total)
connection = SelectConnection(pika.ConnectionParameters('localhost'), on_connected)
try:
# Loop so we can communicate with RabbitMQ
connection.ioloop.start()
except KeyboardInterrupt:
# Gracefully close the connection
connection.close()
# Loop until we're fully closed, will stop on its own
connection.ioloop.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment