How to send messages to multiple topics using DSL in Apache Kafka

I am new to Kafka. I am using Spring Cloud Stream Kafka in my project, also I am writing code in functional way.

I want to consume a message from single input topic, build different models from message and publish each model to a different topic (i.e. 1 model → 1 topic) without using any predicates or branching using DSL.

Can someone please let me know if it is possible to achieve this in Kafka.

Update: Actually I found a way to do this. We can create multiple functions and each function consumes same message from same input topic but while producing we only publish particular model to particular output topic. I see below disadvantages in this approach

  1. I need to create multiple streams to publish models to output topics
  2. My business logic is same in all the functions, it generates all models every time and I need to select particular model that I want to sent to output topic.


public Function<KStream<String, TestEvent1>, KStream<String, TestEvent1>> testFunction1() {
     return input->input; // publishes message to output topic

public Function<KStream<String, TestEvent1>, KStream<String, TestEvent1>> testFunction2() {
     return input->input; // publishes message to output topic


      definition: testFunction1, testFunction2
      destination: test.inputtopic
      destination: test.outputtopic1
      destination: test.inputtopic
      destination: test.outputtopic2

I am not familiar with the details of Spring Cloud Stream Kafka. Using the plain DSL, you would not need to duplicate your business logic, but you could fan-out as follows:

KStream input =;
KStream output = input....; // apply business logic; // first topic; // second topic
//... more topics if needed

Not sure if there is a way in Spring Cloud Stream Kafka to wire up the result to be written into multiple topics (from my understanding, Spring Cloud Stream Kafka will add the calls to to(...) in the background for you to your program).