Search code examples
azure.net-coreazureservicebus

Can we turn messages from Dead Letter queue to Active message?


I have dot net code which read loan-numbers from Azure service queue and calls my API for each loan-number.

This is my code which calls the api

private async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            try
            {
                string loanNumber = Encoding.UTF8.GetString(message.Body);
                _logger.LogInformation($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} LoanNumber:{loanNumber}");

                //API CALL HERE
               await _apiClient.getResult(loanNumber);
               await _queueClient.CompleteAsync(message.SystemProperties.LockToken);
            }
            catch (Exception ex)
            {
                //sending failed messages to Dead Letter queue
                await _queueClient.AbandonAsync(message.SystemProperties.LockToken);
            }
        }

Failed loan-numbers are successfully sent to Dead Letter queue. When the server is down or bad request from API response.

I want to call the api after certain duration on the loan-numbers which are in Dead Letter Queue. Is there any way to convert the messages in Dead Letter queue to active messages after some interval??

I am new to azure. Please help me to resolve the issue.

Thanks in advance.


Solution

  • Is there any way to convert the messages in Dead Letter queue to active messages after some interval??

    Automatically, no. However what you could do is read the messages from dead letter queue and then post them as new message in your main queue.

    As far as automating the whole process, one possible solution would be to run a timer triggered Azure Function that reads messages from a dead letter queue periodically and post them in your main queue.