Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple bindingRoutingKey's for a consumer with Spring Cloud Stream using RabbitMQ

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?

like image 754
Johan Avatar asked Oct 27 '25 19:10

Johan


2 Answers

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

like image 96
Colm O S Avatar answered Oct 30 '25 16:10

Colm O S


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.

like image 22
Gary Russell Avatar answered Oct 30 '25 16:10

Gary Russell