From f78c26d593014d04509680fbc39508245d021dea Mon Sep 17 00:00:00 2001 From: Johann Barbie Date: Mon, 11 Aug 2014 19:38:11 -0700 Subject: [PATCH] hardened amqp consumer --- .../java/org/btc4all/gateway/AmqpConsumerThread.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/btc4all/gateway/AmqpConsumerThread.java b/server/src/main/java/org/btc4all/gateway/AmqpConsumerThread.java index 31efcfb..ddb9c2f 100644 --- a/server/src/main/java/org/btc4all/gateway/AmqpConsumerThread.java +++ b/server/src/main/java/org/btc4all/gateway/AmqpConsumerThread.java @@ -41,9 +41,11 @@ public void run() { while (isActive){ Connection connection = null; QueueingConsumer consumer = null; + Channel channel = null; try { + factory.setAutomaticRecoveryEnabled(true); connection = factory.newConnection(); - Channel channel = connection.createChannel(); + channel = connection.createChannel(); consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); } catch (IOException e) { @@ -76,12 +78,15 @@ public void run() { }else{ System.out.println("undigested message: "+om.writeValueAsString(e)); } - } catch (ShutdownSignalException | ConsumerCancelledException| InterruptedException | IOException e) { + } catch (ShutdownSignalException | ConsumerCancelledException| IOException e) { e.printStackTrace(); + } catch (InterruptedException e2){ + e2.printStackTrace(); isActive = false; } finally{ if (null!=connection){ try { + channel.close(); connection.close(); } catch (IOException e) { }