From b4c2b001ce98e2d6267bca4b18eadda32c0c7f1c Mon Sep 17 00:00:00 2001 From: Hongkai Liu Date: Fri, 3 Jun 2016 10:30:27 -0400 Subject: [PATCH] add clean up method for closing rabbitmq connection fixed eiffel-remrem-publish/issues/23 --- .../eiffel/remrem/publish/helper/RMQHelper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RMQHelper.java b/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RMQHelper.java index 7f8f1dd7..5001b0e0 100644 --- a/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RMQHelper.java +++ b/src/main/java/com/ericsson/eiffel/remrem/publish/helper/RMQHelper.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -41,6 +42,17 @@ } } + @PreDestroy + public void cleanUp() throws IOException { + log.info("RMQHelper cleanUp ..."); + if (rabbitConnection!=null){ + rabbitConnection.close(); + rabbitConnection = null; + } else { + log.warn("rabbitConnection is null when cleanUp"); + } + } + public void send(String routingKey, String msg) throws IOException { giveMeRandomChannel() .basicPublish(exchangeName, routingKey, MessageProperties.BASIC, msg.getBytes());