Search code examples
apache-pulsar

Pulsar: Failure reason while sending message in DLQ


We are using apache-pulsar's retry topic and dead letter topic to handle failures in event processing. In case of a failure in processing, event is retried 3 times via retry topic and if it still fails then message is added in DLQ topic.

Is there a way to add failure message in event while adding that in DLQ after 3 failures?

Example:

Event:
{
  "messageId": "message-1234",
  "data": {...}
}

I want this event to have error field if it goes in DLQ topic after all retries are exhausted. This will help in understanding the reason of failure while analyzing the DLQ.

Event in DLQ:

{
  "messageId": "message-1234",
  "data": {...},
  "errorReason": "Error reason from exception"
}

Solution

  • When you call the reconsumeLaterAsync(), you can pass the properties which is a customized key-value pair list. The properties will be copied to the message that sends to DLQ. Version 2.10.0 is required.

    Here is an example.