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

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.
主站蜘蛛池模板: 镇平县| 赣榆县| 祁连县| 息烽县| 怀仁县| 桐城市| 卫辉市| 绥阳县| 盐亭县| 鲁山县| 黄浦区| 阿城市| 大洼县| 和林格尔县| 吉水县| 亳州市| 密山市| 东乌| 昌江| 阳新县| 巴彦淖尔市| 长岭县| 海晏县| 开化县| 垣曲县| 大英县| 寿阳县| 上林县| 三河市| 登封市| 玉屏| 汪清县| 长顺县| 彭州市| 卢湾区| 鄂州市| 阿瓦提县| 通许县| 翁源县| 新竹县| 博客|