Skip to content

Commit 97c8298

Browse files
committed
stop subscription immediately even when there are pending retries
1 parent fdb4854 commit 97c8298

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

hermes-consumers/src/main/java/pl/allegro/tech/hermes/consumers/consumer/BatchConsumer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ && shouldRetryOnClientError(retryClientErrors, result))
282282
.withStopStrategy(
283283
attempt ->
284284
attempt.getDelaySinceFirstAttempt() > messageTtlMillis
285-
|| Thread.currentThread().isInterrupted())
285+
|| Thread.currentThread().isInterrupted()
286+
|| !consuming)
286287
.withRetryListener(
287288
getRetryListener(
288289
result -> {

hermes-consumers/src/main/java/pl/allegro/tech/hermes/consumers/supervisor/process/ConsumerProcess.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)