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

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.
主站蜘蛛池模板: 资兴市| 镶黄旗| 桦川县| 乐山市| 常德市| 都昌县| 永德县| 宜兰县| 咸丰县| 北辰区| 麻栗坡县| 涟源市| 兴化市| 阿拉善盟| 措美县| 汝州市| 铜川市| 南汇区| 习水县| 宽城| 常熟市| 漯河市| 焉耆| 小金县| 叶城县| 彰武县| 濮阳县| 鹤庆县| 崇文区| 宁国市| 汤阴县| 台前县| 沙洋县| 洪雅县| 临漳县| 阿拉善左旗| 融水| 廊坊市| 镇康县| 珠海市| 濉溪县|