Pausing and Resuming Partitions on Listener Containers
从 2.7 版开始,你可以通过使用侦听器容器中的 pausePartition(TopicPartition topicPartition) 和 resumePartition(TopicPartition topicPartition) 方法来暂停和恢复分配给该使用者的特定分区的使用。暂停和恢复分别在 poll() 之前和之后进行,类似于 pause() 和 resume() 方法。当该分区请求了暂停时,isPartitionPauseRequested() 方法会返回 true。当该分区已实际暂停时,isPartitionPaused() 方法会返回 true。
此外,从 2.7 版开始,ConsumerPartitionPausedEvent 和 ConsumerPartitionResumedEvent 实例会以容器作为 source 属性和 TopicPartition 实例发布。