Send side:
Import pikaconnection = pika. Blockingconnection (Pika. Connectionparameters (' localhost ')) Channel = connection.channel () channel.queue_declare (queue= ' Hello '), Durable=true) # #队列持久化, the queue is restarted and there is no guarantee that the data exists # channel.queue_delete (queue= "Task_queue") # for i in range (+): Channel.basic_publish (exchange= ", routing_key= ' Hello ', body= "Hello world", properties=pika. Basicproperties (delivery_mode=2) # #数据持久化 ) # print ("sent ' hello world! ') Connection.close ()
Receiving end:
Import pikaimport timeconnection = pika. Blockingconnection (Pika. Connectionparameters (host= ' localhost ')) Channel = connection.channel () Channel.queue_declare (queue= ' Hello ', durable=true) # channel.queue_bind (queue= ' Hello ', exchange= ', routing_key= ' hello ') def callback ( Ch, method, properties, body): print ("AAA") # time.sleep (8) print (" [x] received %r" % body) ch.basic_ack (Delivery_tag=method.delivery_tag) # returns the data signal to RABBITMQ. Channel.basic_consume (callback, queue= ' Hello ', no_ack=false) Print (' [*] waiting for messages. to&Nbsp;exit press ctrl+c ') channel.start_consuming ()
Python rabbitmq queue Persistence