Search code examples
spring-cloud-streamamazon-kinesis

Listen to multiple streams into one @StreamListener in Spring Cloud Stream Kinesis


I have multiple Kinesis streams that I need to process. Is there a possibility to use only one @StreamListener method?

If there is, how to configure @StreamListener for this?


Solution

  • You really can have several target destination on a single binding:

    spring.cloud.stream.bindings.input.destination=stream1,stream2,stream3
    

    See docs on the matter: https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.3.RELEASE/reference/html/spring-cloud-stream.html#binding-properties

    destination

    The target destination of a binding on the bound middleware (for example, the RabbitMQ exchange or Kafka topic). If binding represents a consumer binding (input), it could be bound to multiple destinations, and the destination names can be specified as comma-separated String values. If not, he actual binding name is used instead. The default value of this property cannot be overridden.

    There is nothing to do from the code perspective. Your @StreamListener is just listening to that input binding. Everything else is done for you by the framework.