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