Filling in the RabbitMQ in Action Chapter 2 hello world producer

cat-town
Dan Buch 12 years ago
parent 8ac1ef7da5
commit 061c84f554

@ -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())
Loading…
Cancel
Save