Bind RabbitMQ consumer using Spring Cloud Stream to an existing queue
So for now, the work-around that Garry Russell suggested has solved the issue for me.
I've used @RabbitListener
instead of @StreamListenet
this way:
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "TX.Q1", durable = "true"), exchange = @Exchange(value = "TX", type = "topic", durable = "true"), key = "rk1")
.
As a result, the predefined queue TX.Q1 is bind with binding key : rk1 to the exchange TX.
Waiting for updates on the Spring Cloud Steream issue.
I think I found the solution using the @StreamListener
, not using the workaround. Everything is made in the configuration, not in the code.
The configuration I used is the following (it's in .yml, but you can easly translate it in .properties):
spring:
cloud:
stream:
bindings:
input:
binder: <binder_name>
destination: TX
group: Q1
binders:
<binder_name>:
type: rabbit
environment:
spring:
rabbitmq:
host: <host>
port: <port>
virtual-host: <vhost>
username: <username>
password: <password>
rabbit:
bindings:
input:
consumer:
binding-routing-key: rk1
exchange-name: TX
queue-name-group-only: true
bind-queue: true
exchange-durable: true
exchange-type: topic
Using this approach, you don't have to write a particular code to let the RabbitMQ consumer connect to your cluster, this should solve your case.
Hope this helps.