Search code examples
javaazureservicebusservicebusazure-servicebus-queues

Moving messages from dead letter back to topic


Background:

I can read messages from a Dead Letter Queue of a subscription. I gather them in a List and set receiver.complete(message.getLockToken()), which removes the message from DLQ.

And later on, I iterate through this list of gathered messages from DLQ and send them back to topic. At the time of putting them into a List, I do make sure that I create a new object of Message (or BrokeredMessage) before putting it in.

This is all well and good for my own personal account. I see numbers go up. I can also read them fine in another method.

Problem:

I don't know where the messages are ending up when I connect to my company's Topic? They don't go to any subscription. And I don't see any number going up (active count, dead letter count, etc).

Question:

Could this be because no rule is able to process those messages, so they are auto purged? Is this a possibility?


Solution

  • The solution is trivial and is already spread across stackoverflow.

    When I was making a new message object new Message(oldMessage), it was copying all the properties from the old message including DeadLetterReason and DeadLetterErrorDescription. You can get properties by calling this message msg.getProperties().

    This is the reason why messages were going into the ether. I stopped it from copying over, and this resolved the issue.

    On a side note, I have found the answer to my actual question on this link as suggested by @PramodValavala-MSFT

    This was my original question: Could this be because no rule is able to process those messages, so they are auto purged? Is this a possibility?