Reputation: 11
I am trying to implement delayed message (without using rabbitmq plugin) in spring cloud stream but it's not working
I implemented it using spring-boot and it worked fine. Below is the sample code that I did in spring-boot.
I am trying to do the same in spring-cloud-stream but no help. Below are the properties.
Output channel - Producer
spring.cloud.stream.bindings.output.destination=temp-channel
spring.cloud.stream.bindings.output.group=temp-channel-group
Input channel - Consumer
spring.cloud.stream.bindings.input.destination=temp-channel
spring.cloud.stream.bindings.input.group = temp-channel-group
spring.cloud.stream.bindings.input.consumer.exchange-type=direct
spring.cloud.stream.bindings.input.consumer.bind-queue=true
spring.cloud.stream.bindings.input.consumer.binding-routing-
key=foo.bar.key
spring.cloud.stream.bindings.input.consumer.required-groups=final-
channel-group-1
spring.cloud.stream.bindings.input.consumer.auto-bind-dlq=true
spring.cloud.stream.bindings.input.consumer.dlq-ttl=5000
spring.cloud.stream.bindings.input.consumer.dlq-dead-letter-
exchange=final-channel-1
spring.cloud.stream.bindings.input.consumer.dlq-dead-letter-queue=final-
channel-group-1
spring.cloud.stream.bindings.input.consumer.dlq-dead-routing-
key=foo.bar.key
When implemented with spring-boot, I see the message stays in the Temporary queue for the specified time and then moves to Final queue, I want to achieve the same with spring cloud stream. Any inputs would be appreciated.
Upvotes: 0
Views: 1323
Reputation: 174494
You shouldn't be consuming from the temp-channel.
The whole point is you produce to a queue with a TTL, the TTL expires and routes the message to the DLQ; you then consume from the DLQ.
Consumers don't have required-groups
, producers do.
This is what you need:
producer:
spring.cloud.stream.bindings.output.destination=temp-exchange
spring.cloud.stream.bindings.output.producer.required-groups=delayed-group
spring.cloud.stream.rabbit.bindings.output.producer.auto-bind-dlq=true
spring.cloud.stream.rabbit.bindings.output.producer.ttl=5000
spring.cloud.stream.rabbit.bindings.output.producer.dead-letter-exchange=final-dest
spring.cloud.stream.rabbit.bindings.output.producer.dead-letter-queue-name=final-dest.delayed-group
consumer:
spring.cloud.stream.bindings.input.destination=final-dest
spring.cloud.stream.bindings.input.group=delayed-group
Which will create these queues:
temp-exchange.delayed-group
x-dead-letter-exchange: final-dest
x-dead-letter-routing-key: temp-exchange.delayed-group
x-message-ttl: 5000
durable: true
final-dest.delayed-group
Upvotes: 0