Filling in consumer side
This commit is contained in:
parent
061c84f554
commit
7155d76a11
46
sylvilagus/sylvilagus/chapter02/hello_world_consumer.py
Normal file
46
sylvilagus/sylvilagus/chapter02/hello_world_consumer.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pika
|
||||||
|
|
||||||
|
|
||||||
|
def msg_consumer(channel, method, header, body):
|
||||||
|
channel.basic_ack(delivery_tag=method.delivery_tag)
|
||||||
|
if body == 'quit':
|
||||||
|
channel.basic_cancel(consumer_tag='hello-consumer')
|
||||||
|
channel.stop_consuming()
|
||||||
|
else:
|
||||||
|
print(body)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
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)
|
||||||
|
|
||||||
|
channel.queue_declare(queue='hello-queue')
|
||||||
|
channel.queue_bind(queue='hello-queue',
|
||||||
|
exchange='hello-exchange',
|
||||||
|
routing_key='hola')
|
||||||
|
|
||||||
|
channel.basic_consume(msg_consumer,
|
||||||
|
queue='hello-queue',
|
||||||
|
consumer_tag='hello-consumer')
|
||||||
|
|
||||||
|
print('consuming...')
|
||||||
|
channel.start_consuming()
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
Loading…
Reference in New Issue
Block a user