@@ -67,17 +67,7 @@ public void run() {
6767 } finally {
6868 logger .info ("Releasing consumer process thread of subscription {}" , getSubscriptionName ());
6969 refreshHealthcheck ();
70- try {
71- stop ();
72- } catch (Exception exceptionWhileStopping ) {
73- logger .error (
74- "An error occurred while stopping consumer process of subscription {}" ,
75- getSubscriptionName (),
76- exceptionWhileStopping );
77- } finally {
78- onConsumerStopped .accept (getSubscriptionName ());
79- Thread .currentThread ().setName ("consumer-released-thread" );
80- }
70+ stop ();
8171 }
8272 }
8373
@@ -119,7 +109,7 @@ private void process(Signal signal) {
119109 "Stopping main loop for consumer {}. {}" ,
120110 signal .getTarget (),
121111 signal .getLogWithIdAndType ());
122- this . running = false ;
112+ stop () ;
123113 break ;
124114 case RETRANSMIT :
125115 retransmit (signal );
@@ -159,15 +149,27 @@ private void start(Signal signal) {
159149 }
160150
161151 private void stop () {
162- long startTime = clock .millis ();
163- logger .info ("Stopping consumer for subscription {}" , getSubscriptionName ());
164-
165- consumer .tearDown ();
166-
167- logger .info (
168- "Stopped consumer for subscription {} in {}ms" ,
169- getSubscriptionName (),
170- clock .millis () - startTime );
152+ if (!running ) {
153+ return ;
154+ }
155+ this .running = false ;
156+ try {
157+ long startTime = clock .millis ();
158+ logger .info ("Stopping consumer for subscription {}" , getSubscriptionName ());
159+ consumer .tearDown ();
160+ logger .info (
161+ "Stopped consumer for subscription {} in {}ms" ,
162+ getSubscriptionName (),
163+ clock .millis () - startTime );
164+ } catch (Exception exceptionWhileStopping ) {
165+ logger .error (
166+ "An error occurred while stopping consumer process of subscription {}" ,
167+ getSubscriptionName (),
168+ exceptionWhileStopping );
169+ } finally {
170+ onConsumerStopped .accept (getSubscriptionName ());
171+ Thread .currentThread ().setName ("consumer-released-thread" );
172+ }
171173 }
172174
173175 private void retransmit (Signal signal ) {
0 commit comments