'KStream -- iterate LIST of values and send it to output topic

I have a below scenario

KStream<String List<Foo> > fooList = returns me this KStream;

now I have to send this to outputTopic one by one rather than a whole list (i.e) fooList iterate the values alone and push them to the destination topic, so that Individual messages are pushed



Solution 1:[1]

I believe this will work: fooList.flatMapValues(v -> v).to("output");

You can read more about flatMapValues here: https://kafka.apache.org/31/javadoc/org/apache/kafka/streams/kstream/KStream.html#flatMapValues(org.apache.kafka.streams.kstream.ValueMapperWithKey).

From a mathematical point of view, you asking how to flatten the KStream of a List<Foo>. Since flatten is the same as the flatMap of the identify function, this ought to be what you want.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GeoJim