How to pause a specific kafka consumer thread when concurrency is set to more than 1?

纵然是瞬间 提交于 2020-06-29 06:44:31

问题


I am using spring-kafka 2.2.8 and setting concurrency to 2 as shown below and trying to understand how do i pause an consumer thread/instance when particular condition is met.

@KafkaListener(id = "myConsumerId", topics = "myTopic", concurrency=2)
    public void listen(String in) {
        System.out.println(in);
    }

Now, I've two questions.

  1. Would my consumer span two different poll threads to poll the records?

  2. If i'm setting an id to the consumer as shown above. How can i pause a specific consumer thread (with concurrency set to more than 1).

Please suggest.


回答1:


Use the KafkaListenerEndpointRegistry.getListenerContainer(id) method to get a reference to the container.

Cast it to a ConcurrentMessageListenerContainer and call getContainers() to get a list of the child KafkaMessageListenerContainers; you can then pause/resume them individually.

You can determine which topics/partitions each one has using getAssignedPartitions().



来源:https://stackoverflow.com/questions/62364054/how-to-pause-a-specific-kafka-consumer-thread-when-concurrency-is-set-to-more-th

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!