2

Kafka connect has its own set of configurations to programmatically create topics, without relying upon the broker to auto-create new topics.

Is there something similar for the producer (java) API?

YFl
  • 845
  • 7
  • 22
  • 2
    @YFI see if this helps https://stackoverflow.com/a/43580063/2986344 `auto.create.topics.enable` – teedak8s Jun 23 '22 at 01:04
  • 1
    In java, sort of Admin classes can create topic. But may not possible with KafkaProducer class under broker config auto.create.topics.enable=false. – Youngrok Ko Jun 23 '22 at 03:13

2 Answers2

3

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.

Adam Kotwasinski
  • 4,377
  • 3
  • 17
  • 40
2

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.

ChristDist
  • 572
  • 2
  • 8