Pausing and Resuming Partitions on Listener Containers

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

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