Pausing and Resuming Partitions on Listener Containers

从 2.7 版开始,你可以通过使用侦听器容器中的 pausePartition(TopicPartition topicPartition)resumePartition(TopicPartition topicPartition) 方法来暂停和恢复分配给该使用者的特定分区的使用。暂停和恢复分别在 poll() 之前和之后进行,类似于 pause()resume() 方法。当该分区请求了暂停时,isPartitionPauseRequested() 方法会返回 true。当该分区已实际暂停时,isPartitionPaused() 方法会返回 true。

Since version 2.7 you can pause and resume the consumption of specific partitions assigned to that consumer by using the pausePartition(TopicPartition topicPartition) and resumePartition(TopicPartition topicPartition) methods in the listener containers. The pausing and resuming take place respectively before and after the poll() similar to the pause() and resume() methods. The isPartitionPauseRequested() method returns true if pause for that partition has been requested. The isPartitionPaused() method returns true if that partition has effectively been paused.

此外,从 2.7 版开始,ConsumerPartitionPausedEventConsumerPartitionResumedEvent 实例会以容器作为 source 属性和 TopicPartition 实例发布。

Also since version 2.7 ConsumerPartitionPausedEvent and ConsumerPartitionResumedEvent instances are published with the container as the source property and the TopicPartition instance.