Skip to content
Advertisement

How to split message into more messages

if I have a kstream with KVs like <String, List<myobject>> that I obtained from a KStream groupby + aggregate, is there a way to split each of the values of the List<> to get individual messages like <String, myobject>? I was hoping for something like flattening a list that would return individual messages with the same key, but I couldn’t find which method from the kstream (if any) might help. I grouped them to do some transformations more easily, but then, when I want to send those messages to an output topic I’d prefer to send them individually. Thanks!

Advertisement

Answer

.flatMapValues() – Create a new KStream by transforming the value of each record in this stream into zero or more values with the same key in the new stream.

Passing your list to this method, followed up with .to(destinationTopic) should do the trick.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement