Service bus immediately deadletters messages that were not processed
I have a service bus message queue and a function that processes the messages. About a week ago, a strange behavior started to occur: some messages are being sent to the dead letter queue.
From the Azure Function logs, I can see that it is never invoked for such messages.
When I manually remove them from the dead letter queue and insert them again, it works. (Sometimes I need to do this twice.)
I am out of ideas about what I could investigate...
Looking forward to hearing your thoughts. Thanks!
Azure Service Bus
-
Khadeer Ali • 3,830 Reputation points • Microsoft External Staff
2025-03-10T10:05:56.1433333+00:00 Could you check the Dead Letter Reason and Error Description for the affected messages? Also, have there been any recent changes in the function or queue settings?
-
Khadeer Ali • 3,830 Reputation points • Microsoft External Staff
2025-03-11T13:44:34.6933333+00:00 Just following up to see if you had a chance to look into my previous message for additional details.
-
Benjamin Weber • 1 Reputation point
2025-03-11T16:37:39.5233333+00:00 Hello @Khadeer Ali , there was no recent change in the function or queue settings.
These are the deadletter details:
-
Khadeer Ali • 3,830 Reputation points • Microsoft External Staff
2025-03-11T19:32:58.8966667+00:00 Thanks for sharing the details. Since the MaxDeliveryCountExceeded error suggests that the message wasn’t processed successfully, here are a few things to check:
- Function Trigger & Logs – Please verify if the function is actually getting triggered for these messages. Check the Azure Function logs for any errors.
- Queue Settings – If the Max Delivery Count is set to 1, consider increasing it to allow retries before dead-lettering.
- Message Processing – Ensure the function is correctly handling and completing messages. If it fails or times out, the message might be abandoned.
- Function Availability – If the function app was restarted or scaled down, try restarting it and testing again.
Could you try resending a message and see if it gets processed? Let us know what you find!
-
Benjamin Weber • 1 Reputation point
2025-03-12T07:08:36.1366667+00:00 @Khadeer Ali Thanks for the quick responses, I'll go through every point:
- The function is NOT triggered for these messages. Keep in mind that this affects only about 5-10% of the messages in this queue. For these messages, the function is not triggered but the message is moved to the deadletter queue immediately.
- Sadly I can't do that because it is critically that the processing does not happen twice. If it gets re-inserted after a real application error, this might lead to production bugs.
- Yes, these messages do not fail inside the function execution. I can guarantee that from the logs.
- The function is on a consumption plan, so I guess it has to be a supported case that it scales down and gets waked up by a service bus message?
Yes, most of the messages get processed successfully. Even the failed ones are successful when I re-insert them to the queue.
-
Pravallika Kothaveeranna Gari • 160 Reputation points • Microsoft External Staff
2025-03-13T04:37:05.38+00:00 Benjamin Weber, Did you notice any error message or warnings in Application Insights logs?
-
Benjamin Weber • 1 Reputation point
2025-03-13T06:54:22.9466667+00:00 @Anonymous I checked log analytics because it is connected via AppInsights. I see every function execution there (does not matter wether successful or not), and for these messages I see nothing. Do you think the logstream provides further insights?
(It's very hard to read when a lot is going on....)
-
Pravallika Kothaveeranna Gari • 160 Reputation points • Microsoft External Staff
2025-03-13T07:06:10.68+00:00 Benjamin Weber yes, please run the function again and check the logs under log stream.
- Also Check the message processing logic in your Azure Function to ensure that it is correctly handling all types of messages that are being sent to the queue.
- Verify if the messages being sent to the queue are in the expected format and contain all the necessary information for processing.
- Check if there are any specific rules or settings causing messages to be automatically dead-lettered.
- Check if you can implement a retry mechanism in your Azure Function to automatically retry processing failed messages before they are dead-lettered.
-
VenkateshDodda-MSFT • 24,056 Reputation points • Microsoft Employee
2025-03-13T12:52:32.4566667+00:00 @Benjamin Weber Thanks for your patience on this.
Based on the information shared, I understand that messages in the queue are getting move to dead letter without getting consumed by function app with error message 'MaxDelieveryCountExcceded'.
The above error message occurs when the Message couldn't be consumed after maximum delivery attempts.
- Is this a session enabled queue?
- Can you try increasing the Max delivery Count to either 5 or above?
- Do you have multiple clients which are consuming this queue? if yes, could you please check logs of the other client whether message is consumed by it or not since you confirmed that function has not consumed those messages.
- Are you connecting to service bus queue using the connection string? if yes can try regenerating those access key and check whether your function is able to consume the messages.
If you are still facing the Issue I have reached out to you over private message, please do help us with requested information to check and assist you further.
Sign in to comment