.NET 5 Isolate process Azure Service Bus Trigger Message Success Handling

vincent219 251 Reputation points
2021-11-11T09:14:54.337+00:00

In the case of a Service Bus Trigger, an isolated process in .NET 5, how can I propagate the success or failure of a message?

If you use the Service Bus SDK rather than the Azure Function, you can determine whether message processing was successful or not through the DeadLetterMessageAsync and CompleteMessageAsync methods of the ProcessMessageEventArgs class.

Help me

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,397 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,481 Reputation points
    2021-11-12T13:25:02.323+00:00

    @vincent219 ,

    Thanks for reaching out to Q&A.

    You can make use of the messageHandlerOptions.autoComplete property in the host.json file. This property is set to true by default. When set to false, you are responsible for calling MessageReceiver methods to complete, abandon, or deadletter the message. If an exception is thrown (and none of the MessageReceiver methods are called), then the lock remains. Once the lock expires, the message is re-queued with the DeliveryCount incremented and the lock is automatically renewed.

    Azure Functions triggered by Service Bus events auto-complete messages by default. This means a successfully processed message is automatically completed. If an error happens when the message is processed, the message is abandoned and returned to Service Bus. Upon having been delivered a number of times to the function (specified by the maxRetryCount), the message is dead-lettered. Hence, the application has no direct control of the fate of incoming messages.

    Usually there is a possibility to deactivate message auto-completion. In this case, the application must decide on its own what happens with incoming messages. There are usually 4 possibilities: complete, abandon, defer or dead-letter a message. This gives applications a lot more flexibility for error-handling.

    I hope this helps!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.