8000 Make sure missed [server] heartbeats trigger connection recovery · yezijiang/rabbitmq-java-client@ffb2559 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffb2559

Browse files
Make sure missed [server] heartbeats trigger connection recovery
Fixes rabbitmq#57.
1 parent ef8f843 commit ffb2559

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.rabbitmq.client.BlockedListener;
66
import com.rabbitmq.client.Channel;
77
import com.rabbitmq.client.Connection;
8+
import com.rabbitmq.client.MissedHeartbeatException;
89
import com.rabbitmq.client.Recoverable;
910
import com.rabbitmq.client.RecoveryListener;
1011
import com.rabbitmq.client.ShutdownListener;
@@ -378,7 +379,7 @@ private void addAutomaticRecoveryListener() {
378379
ShutdownListener automaticRecoveryListener = new ShutdownListener() {
379380
public void shutdownCompleted(ShutdownSignalException cause) {
380381
try {
381-
if (!cause.isInitiatedByApplication()) {
382+
if (shouldTriggerConnectionRecovery(cause)) {
382383
c.beginAutomaticRecovery();
383384
}
384385
} catch (Exception e) {
@@ -394,6 +395,10 @@ public void shutdownCompleted(ShutdownSignalException cause) {
394395
}
395396
}
396397

398+
protected boolean shouldTriggerConnectionRecovery(ShutdownSignalException cause) {
399+
return !cause.isInitiatedByApplication() || (cause.getCause() instanceof MissedHeartbeatException);
400+
}
401+
397402
/**
398403
* Not part of the public API. Mean to be used by JVM RabbitMQ clients that build on
399404
* top of the Java client and need to be notified when server-named queue name changes

0 commit comments

Comments
 (0)
0