From f41ee2396446f89e15a10417228a55fc9b17b52b Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 14 Mar 2011 12:00:13 +0000 Subject: [PATCH] AMQP-109: catch and log exception during stop --- .../rabbit/listener/BlockingQueueConsumer.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java index f1f1d572..9197fee4 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java @@ -45,7 +45,7 @@ public class BlockingQueueConsumer { private final int prefetchCount; private final boolean transactional; - + private final Channel channel; private final AtomicBoolean cancelled = new AtomicBoolean(false); @@ -54,7 +54,8 @@ public class BlockingQueueConsumer { private final AcknowledgeMode acknowledgeMode; - public BlockingQueueConsumer(Channel channel, AcknowledgeMode acknowledgeMode, boolean transactional, int prefetchCount, String... queues) { + public BlockingQueueConsumer(Channel channel, AcknowledgeMode acknowledgeMode, boolean transactional, + int prefetchCount, String... queues) { this.channel = channel; this.acknowledgeMode = acknowledgeMode; this.transactional = transactional; @@ -154,7 +155,16 @@ public class BlockingQueueConsumer { public void stop() { cancelled.set(true); logger.debug("Closing Rabbit Channel: " + channel); - RabbitUtils.closeMessageConsumer(consumer.getChannel(), consumer.getConsumerTag(), transactional); + try { + RabbitUtils.closeMessageConsumer(consumer.getChannel(), consumer.getConsumerTag(), transactional); + } catch (AmqpException e) { + if (logger.isDebugEnabled()) { + logger.info("Could not close message consumer on shutdown", e); + } else { + logger.info("Could not close message consumer on shutdown (" + e.getClass() + "): " + e.getMessage()); + } + } + // This one never throws exceptions... RabbitUtils.closeChannel(channel); }