kafka consumer to dynamically detect topics added

后端 未结 3 1444
庸人自扰
庸人自扰 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:35

    There was an answer to this in the apache kafka mail archives. I am copying it below:

    The consumer supports a configuration option "metadata.max.age.ms" which basically controls how often topic metadata is fetched. By default, this is set fairly high (5 minutes), which means it will take up to 5 minutes to discover new topics matching your regular expression. You can set this lower to discover topics quicker.

    So in your props you can:

    props.put("metadata.max.age.ms", 5000);
    

    This will cause your consumer to find out about new topics every 5 seconds.

提交回复
热议问题