#! /usr/bin/python # -*- coding: utf-8 -*- import amqplib.client_0_8 as amqp # 创建一个TCP 连接 conn = amqp.Connection(host="localhost:5672 ", userid="guest", password="guest", virtual_host="/", insist=False) # 创建一个通信channel chan = conn.channel() # 创建一个队列 chan.queue_declare(queue="po_box", durable=True, exclusive=False, auto_delete=False) # 创建一个交换机 chan.exchange_declare(exchange="sorting_room", type="direct", durable=True, auto_delete=False) # 绑定 chan.queue_bind(queue="po_box", exchange="sorting_room",routing_key="jason") def recv_callback(msg): print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id) chan.basic_consume(queue='po_box', no_ack=True, callback=recv_callback, consumer_tag="testtag") while True: chan.wait() # 该句不会执行 chan.basic_cancel("testtag") chan.close() conn.close()
rabbitmq使用__python客户端(消息接收者)
最新推荐文章于 2024-06-20 16:05:22 发布