Is there Kafka Producer API configs to set topic auto creation?

Viewed 46
2 Answers

Producer? No, apart from auto-create capability - when actually producer requests a metadata of a topic that does not exist, and that caused the backend to create a topic with default configuration (if enabled). Similar with consumers (fun fact: they can be configured not to create topics even if auto-creation is enabled).

If you want to have finer control, you'd need Kafka Admin instance.

By default, producer API also will auto create topics, when a topic doesn't exist, and a producer trying to publish a message for the first time. But it is not recommended, as it may be created with default configuration values set at broker side.

When auto.create.topics.enable is set to true in Kafka configuration, the following are the circumstances under which a Kafka broker automatically creates a topic.

  • Client requests metadata for a topic
  • Producer sends message to a topic
  • Consumer reads message from a topic

Hope this helps.

Related