- 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.
推薦閱讀
- Mastering ServiceStack
- Python自動化運維快速入門
- Mastering Entity Framework
- 老“碼”識途
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- Nginx實戰:基于Lua語言的配置、開發與架構詳解
- Visual Basic程序設計上機實驗教程
- Unity 2017 Mobile Game Development
- Advanced Express Web Application Development
- 開源項目成功之道
- 智能手機故障檢測與維修從入門到精通
- 單片機原理及應用技術
- Fastdata Processing with Spark
- Java 9 Programming By Example
- Android系統下Java編程詳解