0

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.

Delayed message in RabbitMQ

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.

Yogesh Prajapati
  • 4,770
  • 2
  • 36
  • 77
J.K
  • 11
  • 3
  • So what happened with this prop, `final-channel-1` Exchange and `final-channel-group-1` Queue have been created and binded? Are `x-dead-letter-exchange` and `x-dead-letter-routing-key` and `x-message-ttl` be configured in Queue's arg? – menya Aug 14 '19 at 03:30

1 Answers1

0

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
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks Gary for detailed info. I did try your suggestion and it is not working as expected. It is only creating "Queue final-dest.anonymous.2m9ib1fIS82rTSAIcKLegg" x-queue-master-locator: client-local exclusive: true auto-delete: true – J.K Aug 14 '19 at 20:09
  • That's an anonymous queue for a consumer with no group. You must add a consumer group to get the proper naming - see my answer. The temporary queue with TTL is created by the producer side; via the required groups property. Pay attention to the `letter-queue-name=final-dest.delayed-group`. That is the queue naming convention `.`. – Gary Russell Aug 14 '19 at 20:45
  • Hi Russell, I was trying Output, Input declarations and it didn't work. Today I came to know about latest api Source, Sink and tried, it worked. Thanks much. – J.K Aug 16 '19 at 00:34