- 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.
推薦閱讀
- TypeScript Essentials
- CMDB分步構(gòu)建指南
- Blender 3D Incredible Machines
- Windows內(nèi)核編程
- INSTANT Yii 1.1 Application Development Starter
- Java并發(fā)編程:核心方法與框架
- Python程序設(shè)計(jì)開發(fā)寶典
- PhoneGap 4 Mobile Application Development Cookbook
- R語言實(shí)戰(zhàn)(第2版)
- Node.js實(shí)戰(zhàn):分布式系統(tǒng)中的后端服務(wù)開發(fā)
- Visual FoxPro程序設(shè)計(jì)實(shí)驗(yàn)教程
- TensorFlow.NET實(shí)戰(zhàn)
- Mastering Responsive Web Design
- Java EE應(yīng)用開發(fā)及實(shí)訓(xùn)
- Learning ArcGIS Geodatabases