Producers
Import pika#coding=utf8credentials = Pika. Plaincredentials (' guest ', ' password ') connection = Pika. Blockingconnection (Pika. Connectionparameters (' IP ', 5672, '/', credentials)) channel = Connection.channel () channel.queue_declare (queue= ' Hello ') channel.basic_publish (exchange= ', routing_key= ' Hello ', body= ' rabbitmq test! ') Print ("Start queue") Connection.close ()
Consumers
Import pika#coding=utf8credentials = Pika. Plaincredentials (' guest ', ' password ') connection = Pika. Blockingconnection (Pika. Connectionparameters (' IP ', 5672, '/', credentials)] Channel = Connection.channel () # RABBITMQ The consumer still uses this method to create the queue. This means: if not, create it. and send the truth to the end. The goal is to ensure that the queue is bound to have channel.queue_declare (queue= ' hello ') # callback after receiving the message def callback (ch, method, properties, body): print ("[ X] Received%r "% body" channel.basic_consume (callback, queue= ' Hello ', no_ack=true) print (' [*] waiting for messages. ') Channel.start_consuming ()
Python Test Rabbitmq Simple example