<div dir="ltr">I'm having trouble understanding how to properly code the "handleCancel" call back service in case of an event of a consumer cancel notification occurs. I'm using Java client. First, I have a service that invokes the structure below. I have several services that invokes the below service based on how many queues I have setup on the broker. In my understanding, the "handleCancel" service will be invoke when the master node fails. I'm trying to understand what I need to code in the "handleCancel" service. In the "handleCancel" service, I only have the "consumerTag" information. How will I know the queue that it's associated with so that I can pass this information to the invoking service that'll "re-subscribe" to the queue.<div>
<br></div><div>try {</div><div><br></div><div><div> ConnectionFactory factory = new ConnectionFactory();</div><div><span class="" style="white-space:pre"> </span>factory.setUri(strFactoryURI);</div><div><span class="" style="white-space:pre"> </span>Connection conn = factory.newConnection();</div>
<div><span class="" style="white-space:pre"> </span>Channel channel = conn.createChannel();</div></div><div><br></div><div><p class="MsoNormal" style="text-indent:0.5in">channel.queueDeclare(strQueueName,
true, false, false, null);</p>
<p class="MsoNormal">
</p>
<p class="MsoNormal">
//Callback to handle unexpected issue with the Broker</p>
<p class="MsoNormal">
Consumer consumer = new QueueingConsumer(channel)</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
@Override public void handleCancel(String consumerTag) throws
IOException </p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
// how to handle unexpected
cancellation from broker</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal">
};</p>
<p class="MsoNormal">
</p>
<p class="MsoNormal">
// Dispatch the message</p>
<p class="MsoNormal">
channel.basicConsume(strQueueName, false,</p>
<p class="MsoNormal">
new DefaultConsumer(channel) {</p>
<p class="MsoNormal">
@Override public void handleDelivery(String consumerTag,</p>
<p class="MsoNormal">
Envelope envelope,</p>
<p class="MsoNormal">
AMQP.BasicProperties props,</p>
<p class="MsoNormal">
byte[] body)</p>
<p class="MsoNormal">
throws IOException</p>
<p class="MsoNormal">
{ // execute code to invoke service on 1.0 to persiste the
message }</p>
<p class="MsoNormal">
});</p><p class="MsoNormal"><br></p><p class="MsoNormal">}</p><p class="MsoNormal"><br></p><p class="MsoNormal">thanks,</p><p class="MsoNormal">Phil</p></div></div>