Search code examples
javaapache-kafkaapache-kafka-streams

A Kafka Stream contains List<Employee>, I want to create a unpacked output stream with Employee objects only


The Kafka stream contains a List<Employee> and I want to process the stream as the new Kafka Stream will contain the all Employee from the List<Employee>.

In nutshell I want to unpack the Employee List from existing stream and put individual Employee object into a new stream

I am trying to use the flatMapValues(K,V) function in Kafka Java Library.

Basically I need to unpack the List<Employee> and place the individual object into the Kafka Stream.

I also tried with the forEach loop on the Kafka stream but it's not working.

I saw the documentation for using the flatMapValues() but not sure how to use it.


Solution

  • If you return the list from the flatMapValues function, it will get expanded into individual records.

    You may need to add a Produced.withValueSerde in order to set the appropriate serializer for individual objects rather than a list of them.