Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move a service bus messge to deadletter in service bus queue trigger function

How can we move a service bus queue message to the dead letter through service bus queue trigger function

like image 724
jaas Avatar asked Apr 13 '20 15:04

jaas


1 Answers

https://github.com/Azure/azure-webjobs-sdk/issues/1986#issuecomment-433960534

In v3, you can bind to the MessageReceiver class, which exposes methods like DeadLetter, Abaondon, Complete, etc. Example:

public static async Task ProcessMessage(
   [ServiceBusTrigger("myqueue")] string message, int deliveryCount,
   MessageReceiver messageReceiver,
   string lockToken)
{
   . . .
   await messageReceiver.DeadLetterAsync(lockToken);
   . . .
}

In this example, the message is bound as a string and the various message properties including lockToken are bound as params. You can also bind the message as a Message Type and access the requisite message properties from there. In v2 the ServiceBus SDK exposed these message methods directly on the BrokeredMessage class itself, but in the latest version of their SDK those methods no longer exist, meaning you have to bind to MessageReceiver to access them.

Edit you also need to set AutoComplete to false when you do this. https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp#configuration

like image 62
Alex AIT Avatar answered Sep 28 '22 05:09

Alex AIT