kafka consumer to dynamically detect topics added

后端 未结 3 1452
庸人自扰
庸人自扰 2021-01-06 03:04

I\'m using KafkaConsumer to consume messages from Kafka server (topics)..

  • It works fine for topics created before starting Consumer code...

But

3条回答
  •  青春惊慌失措
    2021-01-06 03:33

    You can hook into Zookeeper. Check out the sample code. In essence, you will create a watcher on the Zookeeper node /brokers/topics. When new children are added here, it's a new Topic being added, and your watcher will get triggered.

    Note that the difference between this and the other answer is that this one is a trigger where the other is a polling -- this one will be as close to real-time as possible, the other will be within whatever your polling interval is at best.

提交回复
热议问题