当客户端channel把消费者和queue绑定,然后channel再把queue删掉时,这个事件是可以监听到的:
private final String queue = "cancel_notification_queue";
public void testConsumerCancellationNotification() throws IOException,
InterruptedException {
final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);
channel.queueDeclare(queue, false, true, false, null);
Consumer consumer = new QueueingConsumer(channel) {
@Override
public void handleCancel(String consumerTag) throws IOException {
try {
result.put(true);
} catch (InterruptedException e) {
fail();
}
}
};
channel.basicConsume(queue, consumer);
channel.queueDelete(queue);//删除queue
assertTrue(result.take());
}