Skip to content

Commit

Permalink
add clean up method for closing rabbitmq connection
Browse files Browse the repository at this point in the history
fixed eiffel-remrem-publish/issues/23
  • Loading branch information
hongkailiu committed Jun 3, 2016
1 parent e02b0e7 commit b4c2b00
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit b4c2b00

Please sign in to comment.