From 061c84f55434945eb32225234d33e28c0a4b3c0a Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 14 Nov 2012 07:43:11 -0500 Subject: [PATCH] Filling in the RabbitMQ in Action Chapter 2 hello world producer --- .../chapter02/hello_world_producer.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sylvilagus/sylvilagus/chapter02/hello_world_producer.py diff --git a/sylvilagus/sylvilagus/chapter02/hello_world_producer.py b/sylvilagus/sylvilagus/chapter02/hello_world_producer.py new file mode 100644 index 0000000..4ee5094 --- /dev/null +++ b/sylvilagus/sylvilagus/chapter02/hello_world_producer.py @@ -0,0 +1,34 @@ +from __future__ import print_function + +import sys + +import pika + + +def main(args=sys.argv[:]): + credentials = pika.PlainCredentials('guest', 'guest') + conn_params = pika.ConnectionParameters('localhost', + credentials=credentials) + conn_broker = pika.BlockingConnection(conn_params) + channel = conn_broker.channel() + channel.exchange_declare(exchange='hello-exchange', + type='direct', + passive=False, + durable=True, + auto_delete=False) + + msg = args[1] + msg_props = pika.BasicProperties() + msg_props.content_type = 'text/plain' + + channel.basic_publish(body=msg, + exchange='hello-exchange', + properties=msg_props, + routing_key='hola') + print('published {!r}'.format(msg)) + + return 0 + + +if __name__ == '__main__': + sys.exit(main())