@@ -292,6 +292,24 @@ public boolean isInExpectedState() {
292
292
return isRunning () || isStoppedNormally ();
293
293
}
294
294
295
+ @ Override
296
+ public void pause () {
297
+ super .pause ();
298
+ KafkaMessageListenerContainer <K , V >.ListenerConsumer consumer = this .listenerConsumer ;
299
+ if (consumer != null ) {
300
+ consumer .wakeIfNecessary ();
301
+ }
302
+ }
303
+
304
+ @ Override
305
+ public void resume () {
306
+ super .resume ();
307
+ KafkaMessageListenerContainer <K , V >.ListenerConsumer consumer = this .listenerConsumer ;
308
+ if (consumer != null ) {
309
+ this .listenerConsumer .wakeIfNecessary ();
310
+ }
311
+ }
312
+
295
313
@ Override
296
314
public Map <String , Map <MetricName , ? extends Metric >> metrics () {
297
315
ListenerConsumer listenerConsumerForMetrics = this .listenerConsumer ;
@@ -369,7 +387,7 @@ protected void doStop(final Runnable callback, boolean normal) {
369
387
if (isRunning ()) {
370
388
this .listenerConsumerFuture .addCallback (new StopCallback (callback ));
371
389
setRunning (false );
372
- this .listenerConsumer .wakeIfNecessary ();
390
+ this .listenerConsumer .wakeIfNecessaryForStop ();
373
391
setStoppedNormally (normal );
374
392
}
375
393
}
@@ -1303,7 +1321,7 @@ protected void pollAndInvoke() {
1303
1321
ConsumerRecords <K , V > records = doPoll ();
1304
1322
if (!this .polling .compareAndSet (true , false ) && records != null ) {
1305
1323
/*
1306
- * There is a small race condition where wakeIfNecessary was called between
1324
+ * There is a small race condition where wakeIfNecessaryForStop was called between
1307
1325
* exiting the poll and before we reset the boolean.
1308
1326
*/
1309
1327
if (records .count () > 0 ) {
@@ -1521,12 +1539,18 @@ private void checkRebalanceCommits() {
1521
1539
}
1522
1540
}
1523
1541
1524
- void wakeIfNecessary () {
1542
+ void wakeIfNecessaryForStop () {
1525
1543
if (this .polling .getAndSet (false )) {
1526
1544
this .consumer .wakeup ();
1527
1545
}
1528
1546
}
1529
1547
1548
+ void wakeIfNecessary () {
1549
+ if (this .polling .get ()) {
1550
+ this .consumer .wakeup ();
1551
+ }
1552
+ }
1553
+
1530
1554
private void debugRecords (@ Nullable ConsumerRecords <K , V > records ) {
1531
1555
if (records != null ) {
1532
1556
this .logger .debug (() -> "Received: " + records .count () + " records" );
@@ -2427,7 +2451,7 @@ private void handleNack(final ConsumerRecords<K, V> records, final ConsumerRecor
2427
2451
2428
2452
private void nackSleepAndReset () {
2429
2453
try {
2430
- Thread . sleep ( this .nackSleep );
2454
+ ListenerUtils . stoppableSleep ( KafkaMessageListenerContainer . this . thisOrParentContainer , this .nackSleep );
2431
2455
}
2432
2456
catch (@ SuppressWarnings (UNUSED ) InterruptedException e ) {
2433
2457
Thread .currentThread ().interrupt ();
0 commit comments