rabbitmq
#生产者
import pika
connection =pika.BlockingConnection(pika.ConnectionParameters(hotst='localho#封装socket逻辑部分
channel=connection.channel() #句柄,收发数据
channel.queue_declare(queue='hello') #创建队列,hello是名字
channel.basic_publish(exchange='',routong_key='hello',body='Hello world!')
#exchange 交换机,路由的作用(多个队列时用exchange)
#routing-key队列名字
#body,发送的内容
print("[x] Sent 'Hello World!'")
connection.close()
#消费者
import pika
connection =pika.BlockingConnection(pika.ConnectionParameters(hotst='localho#封装socket逻辑部分
channel=connection.channel() #句柄,收发数据
channel.queue_declare(queue='hello') #创建队列,hello是名字,如果有则不会重复创建
def callback(ch,method,properties,body):
print("[x] Received %r" % body)
channel.basic_consume(callback,queue='hello',no_ack=True)
#callback函数名字
#no_ack无应答
print("[x] Waiting form messages,to exit press ctrl+c'")
channel.start_consuming()
浙公网安备 33010602011771号