-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consumers do not create topics automatically #340
Comments
I'll rather see this implemented explicitly via CreateTopics protocol: https://kafka.apache.org/protocol.html#The_Messages_CreateTopics We'll accept PRs for the explicit CreateTopics, see a similar PR for DeleteTopics: |
I think this:
is a bug that probably needs a separate issue/PR, I expect the consumer group creation to halt if the topic does not exist. Also we welcome PRs to address it :) |
I'll admit auto creation is usually considered an anti-pattern!
What do you think the behaviour should be? |
Maybe or not return with an error at creation, I don't have strong opinions... |
I think autocreation could be an option; I'd be concerned about doing it by default. I think returning an error at creation vs crashing is basically the same thing, since returning anything besides an :ok tuple during start_link is going to force the supervisor to crash. I'm fine with it crashing if it cannot find the topic (I would have expected that this would happen already) |
On the server side, kafka has a
auto.create.topics.enable
setting that determines whether a topic can be used "on the fly" without having to create it manually beforehand.In other languages/libraries, such as the kafka-console-consumer "official" CLI that uses the java library, or https://github.com/Shopify/sarama (a pure go implementation), starting a consumer or a consumer group for a non-existing topic will trigger the auto create and start consuming from the newly created topic.
With kafka_ex, topics do not get created automatically.
KafkaEx.fetch
will return:topic_not_found
, which is probably the desired behaviour here (regardless of the auto.create.topics.enable setting)KafkaEx.stream
will also return:topic_not_found
, but with the standard use case of a pipe, you risk running into issuesAfterwards the consumer will get "stuck", even if the topics gets created manually later.
I believe starting a consumer group should follow the expected behaviour and trigger a topic creation.
If that helps, I noticed that in lib/kafka_ex/consumer_group/manager.ex,
KafkaEx.metadata
is called to fetch partition info for every topic. On the other hand, callingKafkaEx.metadata(topic: "topicname")
will trigger the automatic topic creation, and return with metadata for the created topic.I'm not sure though which implications replacing the global metadata call with a series of per-topic metadata calls may have?
The text was updated successfully, but these errors were encountered: