Given: DSL topology with KStream::transform
. As part of Transformer::transform
execution multiple messages are generated from the input one (KeyValue<String, Message>
).
I probably can return KeyValue<String, List<Message>>
object from the Transformer::transform
and apply flatMapValues
as the next processor in the topology to flat the list. However I'm wondering is it possible to use ProcessorContext::forward
for the same goal, i.e
public KeyValue<String, Message> transform(String key, Message message) {
Iterable<Message> messages = generateMultipleFromOne(message);
messages.forEach(m->context.forward(key, m));
return null;
}
From the javadoc of Transformer.transform(K key, V value):
If more than one output record should be forwarded downstream,
ProcessorContext.forward(Object, Object)
andProcessorContext.forward(Object, Object, To)
can be used.Note that returning a new KeyValue is merely for convenience. The same can be achieved by using
ProcessorContext.forward(Object, Object)
and returning null.