File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
main/java/com/rabbitmq/client
test/java/com/rabbitmq/client/test/functional Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -36,4 +36,12 @@ public interface RecoveryListener {
36
36
* @param recoverable a {@link Recoverable} connection.
37
37
*/
38
38
void handleRecoveryStarted (Recoverable recoverable );
39
+
40
+ /**
41
+ * Invoked before automatic topology recovery starts.
42
+ * This means that the connection and channel recovery has completed
43
+ * and that exchange/queue/binding/consumer recovery is about to begin.
44
+ * @param recoverable a {@link Recoverable} connection.
45
+ */
46
+ default void handleTopologyRecoveryStarted (Recoverable recoverable ) {}
39
47
}
Original file line number Diff line number Diff line change @@ -560,7 +560,10 @@ public void removeConsumerRecoveryListener(ConsumerRecoveryListener listener) {
560
560
}
561
561
562
562
private synchronized void beginAutomaticRecovery () throws InterruptedException {
563
- this .wait (this .params .getRecoveryDelayHandler ().getDelay (0 ));
563
+ final long delay = this .params .getRecoveryDelayHandler ().getDelay (0 );
564
+ if (delay > 0 ) {
565
+ this .wait (delay );
566
+ }
564
567
565
568
this .notifyRecoveryListenersStarted ();
566
569
@@ -576,6 +579,7 @@ private synchronized void beginAutomaticRecovery() throws InterruptedException {
576
579
// don't assign new delegate connection until channel recovery is complete
577
580
this .delegate = newConn ;
578
581
if (this .params .isTopologyRecoveryEnabled ()) {
582
+ notifyTopologyRecoveryListenersStarted ();
579
583
recoverTopology (params .getTopologyRecoveryExecutor ());
580
584
}
581
585
this .notifyRecoveryListenersComplete ();
@@ -650,6 +654,12 @@ private void notifyRecoveryListenersStarted() {
650
654
}
651
655
}
652
656
657
+ private void notifyTopologyRecoveryListenersStarted () {
658
+ for (RecoveryListener f : Utility .copy (this .recoveryListeners )) {
659
+ f .handleTopologyRecoveryStarted (this );
660
+ }
661
+ }
662
+
653
663
private void recoverTopology (final ExecutorService executor ) {
654
664
// The recovery sequence is the following:
655
665
// 1. Recover exchanges
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ public String getPassword() {
170
170
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/135
171
171
@ Test public void thatShutdownHooksOnConnectionFireBeforeRecoveryStarts () throws IOException , InterruptedException {
172
172
final List <String > events = new CopyOnWriteArrayList <String >();
173
- final CountDownLatch latch = new CountDownLatch (2 ); // one when started, another when complete
173
+ final CountDownLatch latch = new CountDownLatch (3 ); // one when started, another when complete
174
174
connection .addShutdownListener (new ShutdownListener () {
175
175
@ Override
176
176
public void shutdownCompleted (ShutdownSignalException cause ) {
@@ -202,6 +202,10 @@ public void handleRecovery(Recoverable recoverable) {
202
202
public void handleRecoveryStarted (Recoverable recoverable ) {
203
203
latch .countDown ();
204
204
}
205
+ @ Override
206
+ public void handleTopologyRecoveryStarted (Recoverable recoverable ) {
207
+ latch .countDown ();
208
+ }
205
209
});
206
210
assertThat (connection .isOpen ()).isTrue ();
207
211
closeAndWaitForRecovery ();
You can’t perform that action at this time.
0 commit comments