生产方(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

相关文章:

  • 2021-11-26
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
  • 2021-11-20
  • 2021-12-02
  • 2021-11-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-01-08
  • 2021-07-28
  • 2022-12-23
相关资源
相似解决方案