How to redirect message to dead-letter queue Azure Service Bus – Azure

by
Ali Hasan
azure-active-directory azure-functions azure-servicebus-queues azureservicebus c#

The Solutions:

Solution 1: Binding to ServiceBusMessageActions

If you’re using the in-process worker and want to redirect a message to a dead-letter queue, you can bind to ServiceBusMessageActions in your function and call its DeadLetterMessageAsync method. This requires binding to ServiceBusMessage rather than just a string.

For example:

[FunctionName("BindingToMessageActions")]
public static async Task Run(
    [ServiceBusTrigger("<queue_name>", Connection = "<connection_name>")]
    ServiceBusReceivedMessage message,
    ServiceBusMessageActions messageActions)
{
    if (!int.TryParse(message.Body.ToString()), out var id))
    {
        await messageActions.DeadLetterMessageAsync(message);
    }
}

Note that this is currently not available in the isolated process model.

Q&A

How to redirect message to dead-letter queue Azure Service Bus

Bind to ServiceBusMessageActions in your function and then call its DeadLetterMessageAsync method.

How to redirect message to dead-letter queue Azure Service Bus if in isolated process model

Unfortunately, this is not yet available in the isolated process model.

Video Explanation:

The following video, titled "10. Send and Receive message from Dead Letter Queue in Azure ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

In this video I will show how we can send the message to dead letter queue in Azure Service Bus queue. Also, how we can read the message ...