Java Apache Kafka Producer Metadata Updater & Retry Logic

后端 未结 1 497
陌清茗
陌清茗 2021-01-23 02:31

I am using Spring for Apache Kafka and have created a service that uses a Kafka Producer (org.apache.kafka.clients.producer) via Spring\'s KafkaTemplate to send messages to a to

相关标签:
1条回答
  • 2021-01-23 03:00

    Kafka Producer retrieves and caches topic/partition metadata before first send. It then periodically tries to refresh this metadata, every metadata.max.age.ms (default=5minutes) for "good" and every retry.backoff.ms for "invalid" topics. These metadata refresh attempts is what you're observing in the log.

    To prevent cache from growing uncontrollably, unused topics are dropped from it after certain period of time according to these source comments. Currently, this expiry period is hardcoded in ProducerMetadata.java to be 5 minutes.

      public class ProducerMetadata extends Metadata {
          private static final long TOPIC_EXPIRY_NEEDS_UPDATE = -1L;
          static final long TOPIC_EXPIRY_MS = 5 * 60 * 1000;
            ...
    

    You can actually observe all this activity by setting producer log level to DEBUG.

    0 讨论(0)
提交回复
热议问题