3

C# .NetCore 2.2 - Azure Service Bus 3.4.0

I have 3 queues in Azure Service Bus with same properties. While sending messages to these queues, the messages in one of the queues always get delivered to Dead letter queues, while other 2 queues receive active messages.

I have tried playing with the properties - increase TTL, maximum delivery count etc. The properties of all 3 queues are same, the only difference is the name of the queues.

I have used this tutorial - https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues

queue properties image

static async Task SendMessagesAsync(int numberOfMessagesToSend) {

try

{


    for (var i = 0; i < numberOfMessagesToSend; i++)

    {

        // Create a new message to send to the queue.

        string messageBody = $"Message {i}";

        var message = new Message(Encoding.UTF8.GetBytes(messageBody));

        Console.WriteLine($"Sending message: {messageBody}");

        // Send the message to the queue.
        await queueClient.SendAsync(message);
    }
}
catch (Exception exception)
{
    Console.WriteLine($"{DateTime.Now} :: Exception: {exception.Message}");
}

}

How do I prevent messages from going to Dead Letter Queue? Why does it happen with only 1 queue, not the other 2?

4 Answers 4

3

When messages are dead-lettered, there is a reason user property gets added. Check that property to see the reason and troubleshoot accordingly. Specifically, check for DeadLetterReason and DeadLetterErrorDescription custom properties.

1
  • Thanks! I checked the message.UserProperties["DeadLetterErrorDescription"] and found out what the problem was. Oct 17, 2019 at 23:26
1

The common reasons for a message to be dead-lettered are

  • Maximum transfer hop count exceeded
  • Session Id Is Null
  • TTLExpiredException
  • HeaderSizeExceeded

The messages might also have got dead-lettered due to some errors while receiving the message from the Queue. As Sean Feldman mentioned, looking into the DeadLetterReason and DeadLetterDescription property will help you diagnose the error reason clearly.

Also try to increase or set the time to live of the message sent if the DeadLetterReason is TTLExpiredException. Because if you have set the time to live of the message to a lower value then it will override the time to live property of the Queue.

Check whether the Queue whether the queue where the messages are getting dead-lettered is a Session enabled queue and the message sent has the Session Id value set.

1

If you find this "Session Id Is Null" being the cause, Disable the session while creating the subscription.

0

Without seeing your app / messages it's hard to help. But probably there's an error with the application that is trying to consume the message. As it could not be completed, the message goes to the dead letter queue.

Log the messages from this particular queue and see if there's any missing required properties. Sometimes you're trying to deserialize to an uncompatible type.

The purpose of the dead-letter queue is to hold messages that cannot be delivered to any receiver, or messages that could not be processed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.