#测试目的: RABBITMQ Message Distribution Polling
#1. Start two receive ports and sleep for 30 seconds in Callbackup.
#2. The send port sends the data.
#3. When the first receive receives the message, the first program aborts immediately.
#4. Check to see if the second receive is received again (normal)
#RabbitMQ queue information will only be canceled after the client acknowledges receipt, otherwise it persists.
#并且体现了RabbitMQ的分发轮询机制, the first one to receive, then to the second, or the first to receive, the second one.
#send End Import pikacredentials = pika. Plaincredentials (' root ', ' Password1 ') Connection = pika. Blockingconnection (Pika. Connectionparameters (' 10.3.151.86 ', 5672, '/', credentials)) Channel = connection.channel () #通过connection实例创建一个channel管道channel. Queue_declare (queue= ' Hello ') #在管道中创建一个队列channel. Basic_publish (exchange= ", routing_key= ' hello ', body= ' hello wfffforld! ') Connection.close () #receive End Import pikaimport timecredentials = pika. Plaincredentials (' root ', ' Password1 ') Connection = pika. Blockingconnection (Pika. Connectionparameters (' 10.3.151.86 ', 5672, '/', credentials)) Channel = connection.channel () Channel.queue _declare (queue= ' hello ') def callback (ch,method,properties,body): #回调函数 time.sleep (           &NBSP); #增加30秒等待 print (" [x] received %r" % body) ch.basic_ack (delivery_tag= Method.delivery_tag) #通知服务端已确认收到channel. Basic_consume ( callback, queue= ' Hello ', # no_ack=true #默认不写是指返回给服务器是否获取数据成功) print (' [*] waiting for messages . to exit press ctrl+c ') channel.start_consuming ()
This article is from the "Learning Journey" blog, so be sure to keep this source http://mingkang.blog.51cto.com/9678221/1976113
Fifth: Python's RABBITMQ message distribution poll