I need to move my BrokeredMessage to deadletter queue forcefully, if I got a custom exception. Here is my code I have used:
public static async Task Run([ServiceBusTrigger("myqueue", Connection = "myservicebus:cs")]BrokeredMessage myQueueItem, TraceWriter log)
{
try
{
// process message logic..
}
catch(CustomException ex)
{
//forcefully dead letter if custom exception occurs
await myQueueItem.DeadLetterAsync();
}
}
But, some times I'm getting MessageLockLost,
exceptions if I call DeadLetterAsync
, AbandonAsync()
etc., explicitly in my code even though the lock was not actually lost.
Can anyone suggest me, what is the best way to move a brokered message to DeadLetter queue to handle custom exceptions.
Thanks.