- Building Data Streaming Applications with Apache Kafka
- Manish Kumar Chanchal Singh
- 160字
- 2022-07-12 10:38:17
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.
推薦閱讀
- Oracle WebLogic Server 12c:First Look
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- Node.js 10實戰
- Java Web基礎與實例教程(第2版·微課版)
- Visual Basic編程:從基礎到實踐(第2版)
- Mastering Articulate Storyline
- Python進階編程:編寫更高效、優雅的Python代碼
- Scala謎題
- Java編程技術與項目實戰(第2版)
- Learning AngularJS for .NET Developers
- R數據科學實戰:工具詳解與案例分析
- PHP 7從零基礎到項目實戰
- Lift Application Development Cookbook
- Python計算機視覺和自然語言處理
- 愛上C語言:C KISS