4

I'd like to configure an input channel in Spring Cloud Stream to be bound to the same exchange (destination) with multiple routing keys. I've managed to get this working with a single routing key like this:

spring:
  cloud:
    stream:
      rabbit:
        bindings:
          input1:
            consumer:
              bindingRoutingKey: key1.#
      bindings:
        input1:
          binder: rabbit
          group: group1
          destination: dest-group1

But I cannot seem to get it working for multiple keys. I've tried this:

spring:
  cloud:
    stream:
      rabbit:
        bindings:
          input1:
            consumer:
              bindingRoutingKey: key1.#,key2.#
      bindings:
        input1:
          binder: rabbit
          group: group1
          destination: dest-group1

But this doesn't seem to work.

I'm using Spring Boot 2.0.1 and Spring cloud dependencies are imported from:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Finchley.RC1</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

Does anyone know how to achieve this?

Johan
  • 37,479
  • 32
  • 149
  • 237

2 Answers2

5

This can be done now by adding a property:

spring.cloud.stream.rabbit.bindings.<channel-name>.consumer.binding-routing-key-delimiter=,

Then you can comma separate the routing keys:

spring.cloud.stream.rabbit.bindings.<channel-name>.consumer.binding-routing-key=key1,key2,key3

Thanks Gary

Reference documentation

Franky
  • 323
  • 2
  • 10
Colm O S
  • 110
  • 1
  • 8
2

It can't be done with properties; but you can declare the additional bindings as beans; see this answer.

There is also a third party "advanced" boot starter that allows you to add declarations in a yaml file. I haven't tried it, but it looks interesting.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179