0

I need two outputs from transformer. How to process multiple outputs from transformer with Kafka DSL? I'd like to get two KStream with different types after transform().

someMethod(KStream<String, Transaction> transaction) {
    transaction
         .transform(()-> new MyTransformer(...))
         // what can I do here?
}


public class MyTransformer implements Transformer<...> {

    public KeyValue<String, Aggregator> transform(String key, Integer value) {
        if (...) {
          context.forward(key1, new A(...), To.child("first_child"))
        } else {
          context.forward(key2, new B(...), To.child("second_child"))
         }
    }
}
Fruit
  • 33
  • 6
  • I'm no expert in Kafka Streams but I think that transform is not intended to do that. If you transform AND forward inside a transform method, you're "hidding" the forwarding, a transformation is having a collateral non-desired effect. Have you checked the method "branch"? In my opinion is what you're looking for, split the original KStream depending on a condition and then work separately with each resulting KStream. An example here https://stackoverflow.com/a/48950756/2553194 – RubioRic Aug 25 '21 at 10:07
  • No, method 'branch' is not my way. I'd like to understood, how to use the third parametr in method "forward" with DSL. – Fruit Aug 26 '21 at 06:52

0 Answers0