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

Spring cloud stream: As a producer with requiredGroups defined can i specify a routingKey for the queue that will be created?


I could not find anything in the documentation regarding my issue. If it is there and I missed it, please point it out to me.

I have a RabbitMQ message producer service using Spring Cloud Stream, and my configuration is as follows:

spring:
  cloud:
    stream:
      bindings:
        outputSink-out-0:
          destination: foo
          producer:
            requiredGroups: bar

The above configuration creates my foo exchange in RabbitMQ and a bar queue with a routing key of #. My question is, how can I configure a specific routing key, such as test.#, for the bar queue?


Solution

  • See the documentation: https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream-binder-rabbit.html#rabbit-prod-props

    spring.cloud.stream.rabbit.bindings.outputSink-out-0.producer.binding-routing-key=...

    bindingRoutingKey

    The routing key with which to bind the queue to the exchange (if bindQueue is true). Can be multiple keys - see bindingRoutingKeyDelimiter. For partitioned destinations, -n is appended to each key. Only applies if requiredGroups are provided and then only to those groups.

    Default: #.