RABBITMQ Message Persistence2016-02-18 11:19 224 people read comments (0) favorite reports Classification:synthesis (a)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
II: Task Distribution & Message Persistence When multiple receivers are enabled if a receive is turned off to ensure that the message has feedback whether it receives the send side
#-*-Coding:utf-8-*-
Pika
cred = Pika. Plaincredentials (' Zxl ', ' pwd ') #账号密码
params = Pika. Connectionparameters (host= ' 192.168.110.233 ', port=5672,credentials=cred) #条件设置
Connection = Pika. Blockingconnection (params) #给定条件
Channel = Connection.channel ()
Channel.queue_declare (queue= ' t_list ', durable=true) #创建一个t_list queue
Range (0,100):
Content = ' ni hao is Hello ' +str (i)
Channel.basic_publish (exchange= ",
Routing_key= ' T_list ',
Body=content,
Properties=pika. Basicproperties (delivery_mode=2) #确保消息持久
)
Print (' Send Hello ')
Print (channel)
Connection.close ()
Receive End
#-*-Coding:utf-8-*-
Pika
Time
cred = Pika. Plaincredentials (' Zxl ', ' pwd ') #账号密码
params = Pika. Connectionparameters (host= ' 192.168.110.233 ', port=5672,credentials=cred) #条件设置
Connection = Pika. Blockingconnection (params) #给定条件
Channel = Connection.channel ()
Channel.queue_declare (queue= ' t_list ', durable=true)
Callback (Ch,method,properties,body):
"[x] Received%r"% (body,)
Time.sleep (2)
CH method. Delivery_tag)
Channel.basic_consume (callback,queue = ' t_list ', No_ack = false) #no_ack Auto answer to False
Print ("Starting")
Channel.start_consuming ()
RABBITMQ message Persistence