Skip to content

Commit

Permalink
Fix using stale channel when broker is down
Browse files Browse the repository at this point in the history
  • Loading branch information
malakaganga committed Jun 13, 2024
1 parent 00f7942 commit 0232f99
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,15 @@ public void destroy() {
@Override
public MessageProducer getProducer() {
RabbitMQProducer producer = new RabbitMQProducer(this);
boolean producerConnectionInvalidated = false;
producer.setId(nextProducerId());
producer.setExchangeName(exchangeName);
producer.setRoutingKey(routingKey);
if (producerConnection == null) {
producerConnectionInvalidated = true;
producerConnection = createConnection();
} else if (!producerConnection.isOpen()) {
producerConnectionInvalidated = true;
producerConnection.abort();
producerConnection = createConnection();
}
Expand All @@ -365,7 +368,7 @@ public MessageProducer getProducer() {
if (log.isDebugEnabled()) {
log.debug(nameString() + " created message producer " + producer.getId());
}
if (channel == null) {
if (channel == null || producerConnectionInvalidated) {
channel = createChannel(producerConnection);
}
producer.setChannel(channel);
Expand Down

0 comments on commit 0232f99

Please sign in to comment.