Skip to content

Instantly share code, notes, and snippets.

@dalitun
Forked from tomas-stefano/receive.py
Created August 28, 2018 07:49
Show Gist options
  • Save dalitun/5b4d1e311b80db7beb349e2e78af18a3 to your computer and use it in GitHub Desktop.
Save dalitun/5b4d1e311b80db7beb349e2e78af18a3 to your computer and use it in GitHub Desktop.
RabbitMQ example in Python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print "[x] Received: %r" % (body,)
channel.basic_consume(callback, queue='hello', no_ack=True)
channel.start_consuming()
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
for i in range(10000):
body = "Hello World! (" + str(i) + ')'
channel.basic_publish(exchange='', routing_key='hello', body=body)
print "[x] Sent! Hello Word!"
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment