0
votes

I'm using spring cloud stream with RabbitMQ. (Spring cloud version is Greenwich) I have one topic with two queues and I want to send messages to each queue using routing key.

But it doesn't work properly.

When I send messages via each @Output channels, the messages go to both of queues. (I want 1 message for 1 queue, but the 1 message goes to 2 queue)

My producer config is below (actual code is in yaml)

Spring.cloud.stream.bindings.output1.destination=topic-a
Spring.cloud.stream.bindings.output1.producer.requiredGroups=queue1
Spring.cloud.stream.bindings.output1.producer.bindingRoutingKey=queue1
Spring.cloud.stream.bindings.output1.producer.routingKeyExpression=queue1

Spring.cloud.stream.bindings.output2.destination=topic-a
Spring.cloud.stream.bindings.output2.producer.requiredGroups=queue2
Spring.cloud.stream.bindings.output2.producer.bindingRoutingKey=queue2
Spring.cloud.stream.bindings.output2.producer.routingKeyExpression=queue2

And my consumer config is below

spring.cloud.stream.bindings.input1.destination=topic-a
spring.cloud.stream.bindings.input1.group=queue1
spring.cloud.stream.bindings.input1.consumer.durableSubscription=true
spring.cloud.stream.bindings.input1.consumer.bindingRoutingKey=queue1

spring.cloud.stream.bindings.input2.destination=topic-a
spring.cloud.stream.bindings.input2.group=queue2
spring.cloud.stream.bindings.input2.consumer.durableSubscription=true
spring.cloud.stream.bindings.input2.consumer.bindingRoutingKey=queue2

I also tried without requiredGorups and bindingRoutingKey only leaving routingKeyExpression alone in producer config.

I gave routingKeyExpression value in yaml to '''queue1''' or '"queue1'".

If I send 'first' message with output1 and 'second' message with output2,

'first' and 'second' messages are in topic-a.queue1. (routing key is displayed as 'topic-a') while same two messages are in topic-a.queue2 too.

Total 4 messages are generated.

What am I wrong?

Any help would be much appreciated.

1

1 Answers

1
votes

You are missing the .rabbit element for rabbitmq-specific binder properties.

See the documentation.

The following properties are available for Rabbit producers only and must be prefixed with spring.cloud.stream.rabbit.bindings.<channelName>.producer..