Python Message Queuing-RABBITMQ and Redis introduction use

Source: Internet
Author: User
Tags rabbitmq

1, RabbitMQ and Ptyhon process queue difference. Process Queue Primary User Python parent-child processes or a unified process with different sub-processes. Rabbit can communicate with each other before different languages, the socket can achieve the same function, but more complex.

2, RabbitMQ message rotation. A producer for multiple consumer times. Messages are automatically rotation to different consumers.

# Author:xiajinqiimport Pikaconnetction= Pika. Blockingconnection (Pika. Connectionparameters ("localhost")) Channel=Connetction.channel () channel.queue_declare (Queue='Hello'# 1 Production, three consumers, will automatically rotation, one of the consumers after the outage, the message will be automatically sent to other consumers processing. Channel.basic_publish (Exchange="', routing_key='Hello', body='Hello world!') Print ("message has been sent") Channel.close () # Author:xiajinqiimport Pikaimport timeconnetction= Pika. Blockingconnection (Pika. Connectionparameters ("localhost")) Channel=Connetction.channel () channel.queue_declare (Queue='Hello') #避免生产者后启动, there is no error in this queue. So in this statement def callback (Ch,method,properties,body):" ":p Aram CH: Pipe Object Memory Address:p Aram method: message to whom the declaration information:p Aram Properties::p Aram Body::return:    " "print (ch,method,properties,body) ch.basic_ack (Delivery_tag=method.delivery_tag) #执行完以后告诉服务端 # time.sleep ( -pass## declaration received call Callbak processing No_ack default to False message is not lost, indicating that the client callback function needs to be processed, and actively told the server has finished processing. True power-off messages are lost #channel.basic_consume (Callback,queue='Hello', no_ack='True') Channel.basic_consume (Callback,queue='Hello') Print ("start receiving Messages") channel.start_consuming ()

3. Service-side Message Persistence statement

Channel.queue_declare (queue='hello1', durable='True') # durable queue Persistence Declaration #  1 production, three consumers, will automatically rotation, one of the consumers after the outage, the message will be automatically sent to other consumers processing. #delivery_mode Message Persistence Declaration channel.basic_publish (Exchange=", routing_key='hello1 ', body='Hello world! ', Properties=pika. Basicproperties (delivery_mode=2))

Python Message Queuing-RABBITMQ and Redis introduction use

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.