Will kafka consumers differentiate events on the same topic, or get all events on that topic?

softwareengineering.stackexchange https://softwareengineering.stackexchange.com/questions/402343

  •  05-03-2021
  •  | 
  •  

Question

How will a kafka consumer differentiate/behave on the type of events that is stored in a given topic ?

Let's say I have a consumer (Consumer1) which is set up to consume from a topic with event of MyType<OneInnerType>, and then I have another consumer (Consumer2) which is set up to consume from that same topic as Consumer1, but which is set up to consume from events of type MyType<AnotherInnerType>.

So, same topic. Two different event types even though they share outer type. Two consumers which is set to consume from either event-type.

What events will Consumer1 and Consumer2 get out ?

Was it helpful?

Solution

Distinguishing between different event types is a pure convention between producers and consumers. Kafka itself knows nothing about types, it only knows untyped topics. Therefore both consumers will receive events of either type. If you want to distribute events of different types to different consumers, you should send them to separate topics.

Licensed under: CC-BY-SA with attribution
scroll top