Search code examples
apache-kafkaapache-kafka-streams

How to make fanout in Apache Kafka?


I need to send message for all consumers, but before detect who should get this message, how to do that using Kafka?

Should I use Kafka stream to filter data then send to consumers? As I know each consumers should be added to unique consumer group, but how to detect in real time, who must receive message ?


Solution

  • Kafka decouples consumer and producer and when you write into a topic, you don't know which consumers might read the data.

    Thus, in Kafka you never "send a message to a consumer", you just write the message into a topic and that's it.

    Consumers just read from topics. Thus, you just need to spin up multiple consumers (with no consumer group.id, or different consumer group.id config) and each consumer will read all data, and thus you fan-out.