<div dir="ltr"><div>Hi All,</div><div><br></div><div>I am working on RabbitMQ HA cluster . I want my client to connect to slave node when the master node goes down. </div><div>I am trying to achieve this using consumer cancel notification.</div>
<div>I am using python amqp 1.4.2 library . I have set the capability 'consumer_cancel_notify' as True in client_properties.</div><div>In basic_consume() I have passed a callback function to on_cancel parameter. But this callback is not called when master goes down.</div>
<div><br></div><div>Can someone tell where I am going wrong.</div><div><br></div><div>Thanks,</div><div>Akhil </div><div><br></div><div><br></div><div>Following is my code : </div><div><br></div><div>import amqp</div><div>
<br></div><div># this is the callback function to receive the messages published to the queue </div><div>def myCallback(message):</div><div> print "messsage received",message.body</div><div><br></div><div># this is the callback Function for consumer cancel notification</div>
<div>def cancelCallback():</div><div> print "cancelCallback called" </div><div> </div><div><br></div><div>cpDict = {"capabilities":{"consumer_cancel_notify": True, },}</div><div>con = amqp.Connection(host ="localhost:5672",userid ="guest",password="guest",client_properties=cpDict)</div>
<div>channel = con.channel() </div><div>channel.exchange_declare(exchange="exchange1",type='direct', durable=True, auto_delete=False)</div><div>channel.queue_declare(queue="bm2_execQ", durable=True,exclusive=True, auto_delete=False)</div>
<div>channel.queue_bind(queue="bm2_execQ",exchange="exchange1", routing_key="bm2_execQ") </div><div>channel.basic_consume(queue="bm2_execQ",callback=myCallback, consumer_tag="bm2_tag",on_cancel=cancelCallback)</div>
<div><br></div><div>msg = amqp.Message("hi")</div><div>msg.properties["content_type"] = "text/plain"</div><div>msg.properties["delivery_mode"] = 2</div><div><br></div><div>channel.basic_publish(msg,"exchange1","bm2_execQ")</div>
<div><br></div><div>while True :</div><div> channel.wait()</div></div>