I have a Spring Cloud Stream application what using the RabbitMQ binder to consume messages (it doesn't produce any). The application.yaml
file looks like this:
spring:
cloud:
stream:
rabbit:
bindings:
x:
consumer:
bindingRoutingKey: x.z.#
queueNameGroupOnly: true
y:
consumer:
bindingRoutingKey: y.z.#
queueNameGroupOnly: true
bindings:
x:
binder: rabbit
group: q1
destination: x
y:
binder: rabbit
group: q2
destination: y
This will create two queues in RabbitMQ:
q1
that is bound to exchange x
with routing key x.z.#
q2
that is bound to exchange y
with routing key y.z.#
I'd like to create a single queue that consumes from multiple exchanges and routing keys. I know that I can't bind an exchange to multiple routing keys from application.yaml
(see this SO question) and thus I suspect that I can't configure Spring Cloud Stream to use multiple destinations (exchanges) for a single binding.
So my question is, can I programmatically declare so that one binding
consumes from multiple exchanges? Is there anything that is required to be retained in the application.yaml
file if doing this?
How should I go about?
You can use exchange-to-exchange binding to satisfy this requirement.
x -> z
y -> z
Then consume from a single queue on z that is bound with #
.
You can define the exchange to exchange bindings in your boot application as @Bean
s.