@@ -453,15 +453,15 @@ private void publishNonResponsiveConsumerEvent(long timeSinceLastPoll, Consumer<
453
453
}
454
454
}
455
455
456
- private void publishConsumerPausedEvent (Collection <TopicPartition > partitions ) {
456
+ void publishConsumerPausedEvent (Collection <TopicPartition > partitions , String reason ) {
457
457
ApplicationEventPublisher publisher = getApplicationEventPublisher ();
458
458
if (publisher != null ) {
459
459
publisher .publishEvent (new ConsumerPausedEvent (this , this .thisOrParentContainer ,
460
- Collections .unmodifiableCollection (partitions )));
460
+ Collections .unmodifiableCollection (partitions ), reason ));
461
461
}
462
462
}
463
463
464
- private void publishConsumerResumedEvent (Collection <TopicPartition > partitions ) {
464
+ void publishConsumerResumedEvent (Collection <TopicPartition > partitions ) {
465
465
ApplicationEventPublisher publisher = getApplicationEventPublisher ();
466
466
if (publisher != null ) {
467
467
publisher .publishEvent (new ConsumerResumedEvent (this , this .thisOrParentContainer ,
@@ -1691,7 +1691,9 @@ private void doPauseConsumerIfNecessary() {
1691
1691
this .consumerPaused = true ;
1692
1692
this .pauseForPending = false ;
1693
1693
this .logger .debug (() -> "Paused consumption from: " + this .consumer .paused ());
1694
- publishConsumerPausedEvent (assigned );
1694
+ publishConsumerPausedEvent (assigned , this .pausedForAsyncAcks
1695
+ ? "Incomplete out of order acks"
1696
+ : "User requested" );
1695
1697
}
1696
1698
}
1697
1699
}
@@ -1702,6 +1704,7 @@ private void resumeConsumerIfNeccessary() {
1702
1704
this .nackWakeTimeMillis = 0 ;
1703
1705
this .consumer .resume (this .pausedForNack );
1704
1706
this .logger .debug (() -> "Resumed after nack sleep: " + this .pausedForNack );
1707
+ publishConsumerResumedEvent (this .pausedForNack );
1705
1708
this .pausedForNack .clear ();
1706
1709
}
1707
1710
}
@@ -2649,6 +2652,7 @@ private void pauseForNackSleep() {
2649
2652
this .logger .debug (() -> "Pausing for nack sleep: " + ListenerConsumer .this .pausedForNack );
2650
2653
try {
2651
2654
this .consumer .pause (this .pausedForNack );
2655
+ publishConsumerPausedEvent (this .pausedForNack , "Nack with sleep time received" );
2652
2656
}
2653
2657
catch (IllegalStateException ex ) {
2654
2658
// this should never happen; defensive, just in case...
@@ -3507,7 +3511,8 @@ public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
3507
3511
}
3508
3512
if (ListenerConsumer .this .commonErrorHandler != null ) {
3509
3513
ListenerConsumer .this .commonErrorHandler .onPartitionsAssigned (ListenerConsumer .this .consumer ,
3510
- partitions );
3514
+ partitions , () -> publishConsumerPausedEvent (partitions ,
3515
+ "Paused by error handler after rebalance" ));
3511
3516
}
3512
3517
}
3513
3518
@@ -3518,7 +3523,7 @@ private void repauseIfNeeded(Collection<TopicPartition> partitions) {
3518
3523
ListenerConsumer .this .logger .warn ("Paused consumer resumed by Kafka due to rebalance; "
3519
3524
+ "consumer paused again, so the initial poll() will never return any records" );
3520
3525
ListenerConsumer .this .logger .debug (() -> "Paused consumption from: " + partitions );
3521
- publishConsumerPausedEvent (partitions );
3526
+ publishConsumerPausedEvent (partitions , "Re-paused after rebalance" );
3522
3527
}
3523
3528
Collection <TopicPartition > toRepause = new LinkedList <>();
3524
3529
partitions .forEach (tp -> {
@@ -3529,7 +3534,7 @@ private void repauseIfNeeded(Collection<TopicPartition> partitions) {
3529
3534
if (!ListenerConsumer .this .consumerPaused && toRepause .size () > 0 ) {
3530
3535
ListenerConsumer .this .consumer .pause (toRepause );
3531
3536
ListenerConsumer .this .logger .debug (() -> "Paused consumption from: " + toRepause );
3532
- publishConsumerPausedEvent (toRepause );
3537
+ publishConsumerPausedEvent (toRepause , "Re-paused after rebalance" );
3533
3538
}
3534
3539
this .revoked .removeAll (toRepause );
3535
3540
ListenerConsumer .this .pausedPartitions .removeAll (this .revoked );
0 commit comments