Fifth: Python's RABBITMQ message distribution poll

Source: Internet
Author: User
Tags rabbitmq

#测试目的: 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.