python使用rabbitmq接收_python – 如何使用Pika发送和接收RabbitMQ消息?

事实证明,我对AMQP的理解是不完整的.

这个想法如下:

客户:

获得连接后的客户端不应该关心除交换机名称和路由密钥之外的任何其他内容.那就是我们不知道最终会进入哪个队列.

channel.basic_publish(exchange='order',

routing_key="order.test.customer",

body=pickle.dumps(data),

properties=pika.BasicProperties(

content_type="text/plain",

delivery_mode=2))

消费者

当通道打开时,我们声明交换和队列

channel.exchange_declare(exchange='order',

type="topic",

durable=True,

auto_delete=False)

channel.queue_declare(queue="test",

durable=True,

exclusive=False,

auto_delete=False,

callback=on_queue_declared)

当队列准备就绪时,在“on_queue_declared”回调是个好地方,我们可以使用我们想要的路由键将队列绑定到交换机.

channel.queue_bind(queue='test',

exchange='order',

routing_key='order.test.customer')

#handle_delivery is the callback that will actually pickup and handle messages

#from the "test" queue

channel.basic_consume(handle_delivery, queue='test')

使用路由密钥“order.test.customer”发送到“订单”交换的消息现在将被路由到“测试”队列,消费者可以在其中获取它.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值