# How to implement N-input and N-output using KStream and spring.cloud.stream

**URL:** <https://forum.confluent.io/t/how-to-implement-n-input-and-n-output-using-kstream-and-spring-cloud-stream/12350>\
**Category:** Kafka Streams\
**Created:** [13 October 2024 18:20 UTC](https://forum.confluent.io/t/how-to-implement-n-input-and-n-output-using-kstream-and-spring-cloud-stream/12350 "2024-10-13T18:20:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amyth](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@amyth](https://forum.confluent.io/u/amyth)\
**Post date:** [13 October 2024 18:20 UTC](https://forum.confluent.io/t/how-to-implement-n-input-and-n-output-using-kstream-and-spring-cloud-stream/12350/1 "2024-10-13T18:20:12Z")

</div>

I am trying to implement an N-input stream and N-output stream  
Where I have multiple input topics and multiple output topics.  
E.g.:  
Input\_topic\_1 ----\> Output\_topic\_1 and Output\_topic\_2  
Input\_topic\_2 -----\> Output\_topic\_2 and Output\_topic\_3  
Input\_topic\_3 -----\> Output\_topic\_1 and Output\_topic\_3  
Single stream works with method signature:

```auto
@Bean
public Function<KStream<String, String>, KStream<String, JsonNode>[]> process()

```

Even BiFunction works for 2 inputs.

```auto
@Bean
public BiFunction<KStream<String, String>, KStream<String, String>, KStream<String, JsonNode>[]> process() {

```

But My use case is to process more than 2 inputs. In Java, there is Function And BiFunction to take input parameters, I have tried using

```auto
@Bean
public Function<KStream<String, String>[], KStream<String, JsonNode>[]> process()

```

And

```auto
@Bean
public Function<List<KStream<String, String>>, KStream<String, JsonNode>[]> process()

```

but App not able to recognize process method:

**app.yaml:**

```auto
spring:
  cloud:
    stream:
      kafka:
        streams:
          binder:
            configuration:
              commit.interval.ms: 1000
              default.key.serde: org.apache.kafka.common.serialization.Serdes$StringSerde
              default.value.serde: org.apache.kafka.common.serialization.Serdes$StringSerde
              num.stream.threads: 2 
            zkNodes: localhost:2181
            brokers: localhost:9092 

          default:
            consumer:
              applicationId: app1
      function:
        definition: process
        bindings:
           process-in-0:
            destination: in-1
           process-in-1:
             destination: in-2
           process-in-2:
             destination: in-3
           process-out-0:
             destination: out-1
           process-out-1:
             destination: out-2
           process-out-2:
             destination: out-3

```

I am sure, something is wrong with the method signature. Please help me to get the correct approach to achieve n-input and n-output. TIA!!

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [17 October 2024 15:14 UTC](https://forum.confluent.io/t/how-to-implement-n-input-and-n-output-using-kstream-and-spring-cloud-stream/12350/2 "2024-10-17T15:14:46Z")

</div>

Using “plain” Kafka Streams, that is certainly possible… I am not familiar with Spring though, and don’t know how to do it there (or if possible with Spring).
