官术网_书友最值得收藏!

Subscription and polling

Consumer has to subscribe to some topic to receive data. The KafkaConsumer object has subscribe(), which takes a list of topics that the consumer wants to subscribe to. There are different forms of the subscribe method.

Let's talk about the subscribe method in detail with its different signatures:

  • public void subscribe(Collection<String> topics): This signature takes a list of topic names to which the consumer wants to subscribe. It uses the default rebalancer, which may affect data processing of the message.
  • public void subscribe(Pattern pattern,ConsumerRebalanceListener listener): This signature takes regex to match topics that exist in Kafka. This process is dynamic; any addition of a new topic matching the regex or deletion of a topic matching the regex will trigger the rebalancer. The second parameter, ConsumerRebalanceListener, will take your own class that implements this interface. We will talk about this in detail.
  • public void subscribe(Collection<String> topics,ConsumerRebalanceListener listener): This takes a list of topics and your implementation of ConsumerRebalanceListner.
主站蜘蛛池模板: 仪征市| 芮城县| 宝山区| 宁陕县| 和硕县| 门头沟区| 万安县| 沂源县| 兴化市| 黔南| 赫章县| 临邑县| 芜湖县| 体育| 大关县| 井冈山市| 黄骅市| 久治县| 南雄市| 内乡县| 凉山| 永嘉县| 萝北县| 阳春市| 阿图什市| 龙泉市| 湛江市| 新龙县| 徐汇区| 揭东县| 仁化县| 天长市| 彭泽县| 思南县| 平利县| 江城| 屏东县| 四川省| 重庆市| 定安县| 吉水县|