发送端:
import 鼠兔 时间=connection pika.BlockingConnection (pika.ConnectionParameters (' localhost ')) 时间=channel connection.channel () channel.queue_declare(队列='你好') #,for 小姐:拷贝范围(100): channel.basic_publish(交换=", ,,,,,,,,,,,,,,,,,,,,,routing_key='你好', ,,,,,,,,,,,,,,,,,,,,,身体=癶ello 世界”) #,打印(“Sent hello 世界!”) connection.close ()
接收端:
# !/usr/bin/env python import 鼠兔 import 时间 时间=connection pika.BlockingConnection (pika.ConnectionParameters(主机=' localhost ')) 时间=channel connection.channel () channel.queue_declare(队列='你好') #,channel.queue_bind(队列=愫谩?交换=" routing_key='你好') def 回调(ch、,方法,属性,,身体): ,,,印刷(“aaa”) ,,,time . sleep (8) ,,,(打印”,[x] Received % r”, %,身体) channel.basic_consume(回调, ,,,,,,,,,,,,,,,,,,,,,队列='你好', ,,,,,,,,,,,,,,,,,,,,,no_ack=False) 打印(',[*]Waiting for 消息只用exit press CTRL + C”) 以前channel.start_consuming() > <>以前