Search code examples
spring-bootspring-cloud-streamspring-cloud-stream-binder-kafka

Is it possible to configure multiple bindings to the same Processor in Spring Cloud Stream?


I have a simple Spring Integration flow that binds to Processor for input and output.

I've configured the Kafka binder to map an input and output topic. That works perfectly.

Say I want to bind 3 Kafka topics to input, resulting in 3 configured consumers pulling from three separate kafka topics, which would then be processed by my SI flow.

Is it possible to map multiple Kafka topics to my Processor's input? If so, how would that configuration look?


Solution

  • If the destination property is a comma-delimited list a listener container will be created for each destination and bound to the same listener.

    You can also set the multiplex property to true so we only have one container listening on multiple topics.

    spring.cloud.stream.bindings.foo.consumer.multiplex=true.

    /**
     * When set to true, the underlying binder will natively multiplex destinations on the
     * same input binding. For example, in the case of a comma separated multiple
     * destinations, the core framework will skip binding them individually if this is set
     * to true, but delegate that responsibility to the binder.
     *
     * By default this property is set to `false` and the binder will individually bind
     * each destinations in case of a comma separated multi destination list. The
     * individual binder implementations that need to support multiple input bindings
     * natively (multiplex) can enable this property.
     */
    private boolean multiplex;
    

    You have to set the multiplex property to enable it.