Ömer
Ömer

Reputation: 84

Spring Cloud Stream RabbitMQ Binder Consumer Properties republishToDlq not working for me

Using below configuration aplication.yml, for a consumer application through Spring Cloud Stream 3.0.12.RELEASE and Spring Boot 2.5.6

spring:
  main:
    web-application-type: none
  cloud:
    stream:      
      bindings:
        consumeSomething-in-0:
          destination: some-topic-vhost2
          group: some-events
          binder: local_rabbit
          consumer:
            max-attempts: 1
            auto-bind-dlq: true
            dlq-ttl: 50000
            republishToDlq: true

I am trying to manage error handling with republishToDlq to route the messages which throw exception together with exception stack trace. In the document it is told that;

2. RabbitMQ Binder Overview

..." In addition, republishToDlq causes the binder to publish a failed message to the DLQ (instead of rejecting it). This feature lets additional information (such as the stack trace in the x-exception-stacktrace header) be added to the message in headers."

When I check the queue some-topic-vhost2.some-events.dlq, I figure out that the message which throws exception routed to that queue. It is OK. But the exception stack trace is not added as a header. And also, the applicaiton send as a warning below,

o.s.c.s.b.r.RabbitMessageChannelBinder   : 'republishToDlq' is true, but the 'DLX' dead letter exchange is not present; disabling 'republishToDlq'

What is wrong with this config. What should I do to enable republishToDlq

Upvotes: 0

Views: 2304

Answers (2)

sobychacko
sobychacko

Reputation: 5924

In addition to what Oleg mentioned above, I think there is a slight problem with your configuration where you set rabbit binding properties. There are a few Rabbit consumer-specific properties that must be set on the rabbit binding itself. See below and notice the rabbit indirection in the configuration. max-attempts and other binding properties can stay where they are in your configuration.

spring:
  cloud:
    stream: 
      bindings:
          consumeSomething-in-0:
            destination: some-topic-vhost2
            group: some-events
            binder: local_rabbit
            consumer:
              max-attempts: 1 
      rabbit    
        bindings:
          consumeSomething-in-0:
            consumer:
              auto-bind-dlq: true
              dlq-ttl: 50000
              republishToDlq: true

Upvotes: 1

Oleg Zhurakousky
Oleg Zhurakousky

Reputation: 6126

You probably missing some configuration. Here is a working example I provided for a different question - https://github.com/olegz/stream-function-samples/tree/main/stream-rabbit-dlq Although it this example is specific to RoutingFunction, it is just like any other function, so you can easily retrofit it to your case by changing all properties that use functionRouter-in-0 to your consumeSomething-in-0.

Upvotes: 0

Related Questions