I am trying to get my consumer to dynamically update its consumption.
Let me give you a more concrete example using animals. Imagine that I have a pet store, every topic is a type of animal (e.g. dogs, cats, fish). The primary responsibility of my Kafka consumer is to grab whatever log/record/message we have in Kafka and store them into a database.
Suppose that my consumer is actively consuming on dogs
and cats
topics and everything works fine, now there is a new type of animal coming into the store and a new topic is generated in the Kafka cluster. How do I notify my consumer that a new topic has been added?
I have two proposals and I want to see which one do you think is better? Or if there is a better 3rd option, please let me know.
1.) Producer sends a http request to consumer and let consumer knows that producer is about to create a new topic so consumer can act accordingly. The problem with this approach is that, there is a race condition. There is a chance that consumer will try to consume before the topic is even created. (I actually just discovered that if I have auto.topic.creation.enable
set to true, the race condition isn't really a problem.)
2.) Create an extra topic called topic_updates
in the Kafka cluster. So whenever producer has successfully committed a message to the Kafka cluster, it broadcasts the news through this topic_updates
, maybe a simple string will do. Consumer is actively listening to this topic updates.
3.) I don't know, ideally I wish that Kafka can emit an event whenever a new topic is created.
Thank you in advance