Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually send message to service bus dead letter queue in Azure Function?

The Azure Service Bus Queue triggered function would perform a default policy for sending message into the dead letter queue if message is poisoned. However, is there anyway that we could manually send the message to dead letter queue? There are couple of times that we wouldn't want Azure Function to perform its default policy due to some kind of internal or business exception, we would like to bind additional information to our message and manually send it to our Azure Service Bus Deadletter Queue.

In a previous version where it's using BrokeredMessage object, there is a method called

BrokeredMessage msg;
msg.DeadLetter();

However, in the most recent Functino 2.X, where it's using the Message object, that doesn't have this method somehow...

like image 257
Kev D. Avatar asked Dec 15 '25 05:12

Kev D.


1 Answers

With Functions 2.0 you use the .NET Standard Service Bus client. Message no longer has operations such as dead-lettering. Instead, you need to add an additional parameter of MessageReceiver type to be able to use DeadletterAsync() method it provides. You can find an example of how to use message receiver in my post.

like image 119
Sean Feldman Avatar answered Dec 16 '25 21:12

Sean Feldman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!