Faraz
Faraz

Reputation: 6275

Read All Dead Letter Queue messages

I am able to read DLQ messages. There are 4000 of them. And I am sure I am only able to read 250 or 270 of them. Rest of the messages just repeat themselves. I think it has to do with receive time:

IMessage msg = deadletterReceiver.receive(Duration.ofMinutes(10));

I do it for seconds, or minutes, doesn't matter. I am only able to read 250-260 of them and then the same ones repeat. Is there a different way to read all 4k DLQ messages?

I don't want to do this deadletterReceiver.completeAsync(message.getLockToken()); yet as it will delete the messages and those DLQ messages are priceless.

Upvotes: 0

Views: 626

Answers (1)

Sean Feldman
Sean Feldman

Reputation: 26012

What's happening is the following - dead-letter queue has a MaxLockDuration during which you're supposed to complete message processing. If you don't, the message will re-appear in the queue and you'll consume it again. The maximum locking time for a message is 5 minutes. You could read in batches, do what you need to do with those dead-lettered messages, and complete them. All within the MaxLockDuration time.

I also recommend to ensure you do it transactionally in order not to lose any dead-lettered messages.

Edited by the questioner:

This is the most relevant part in the document:

When a message is locked, other clients receiving from the same queue or subscription can take on locks and retrieve the next available messages not under active lock. When the lock on a message is explicitly released or when the lock expires, the message pops back up at or near the front of the retrieval order for redelivery.

edit2: I don't how this important document got lost: Here it is again.

Upvotes: 1

Related Questions