生产方(Fanout_Publisher.py)

 1 # __author__ = 'STEVEN'
 2 import pika
 3 #开启socket
 4 connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
 5 #开启一个通道
 6 channel = connection.channel()
 7 #这里不用再创建队列
 8 channel.exchange_declare(exchange='logs',exchange_type='fanout')
 9 #消息内容
10 mes = 'publisher said hello'
11 #发布消息exchange='logs'是给他起了一个名字,随便什么都行
12 channel.basic_publish(exchange='logs',routing_key='',body=mes)
13 print('[x] send the mes%s to queue'%mes)
14 #关闭连接
15 connection.close()
View Code

相关文章: