Filling in the RabbitMQ in Action Chapter 2 hello world producer
This commit is contained in:
parent
8ac1ef7da5
commit
061c84f554
34
sylvilagus/sylvilagus/chapter02/hello_world_producer.py
Normal file
34
sylvilagus/sylvilagus/chapter02/hello_world_producer.py
Normal file
@ -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…
Reference in New Issue
Block a user