Filling in consumer side

This commit is contained in:
Dan Buch 2012-11-14 07:52:32 -05:00
parent 061c84f554
commit 7155d76a11

View 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())