1

I am encountering one major road block issue when trying to use ServiceBusTrigger in azureFunction. I am trying to abandon, or deadletter, a service bus message in V2 ServiceBusTrigger, How can I do so? I've tried the following solution, but I didn't get anywhere. Here is the codeSample I used:

public async static Task Run(Message myQueueItem, TraceWriter log, ExecutionContext context)
{
   log.Info($"C# ServiceBus queue trigger function processed message delivery count: {myQueueItem.SystemProperties.DeliveryCount}");

   QueueClient queueClient = new QueueClient("[connectionstring]","[queueName]");

   ////await queueClient.DeadLetterAsync(myQueueItem.SystemProperties.LockToken);
   await queueClient.AbandonAsync(myQueueItem.SystemProperties.LockToken);
 }

Solution 1: I tried to substitute Message myQueueItem for BrokeredMessage like in V1, I then can call myQueueItem.Abandon, or deadletter, on the message lever. However It came back with exception:

Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. System.Private.DataContractSerialization: There was an error deserializing the object of type Microsoft.ServiceBus.Messaging.BrokeredMessage. The input source is not correctly formatted. System.Private.DataContractSerialization: The input source is not correctly formatted."

At least I can go one step further. to solution 2. Solution 2: is to use:

 QueueClient queueClient = new QueueClient("[connectionstring]","[queueName]");      
 ////await queueClient.DeadLetterAsync(myQueueItem.SystemProperties.LockToken);
 await queueClient.AbandonAsync(myQueueItem.SystemProperties.LockToken);

I can use the lock provided in the Message Object, however, when I try to send it with queueClient, It said the message gone from the queue. or no longer available.

Can anybody let me know if i am on the right track? If I am not, please kindly guide me in the right track.

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
mslugx
  • 724
  • 7
  • 15

1 Answers1

0

Service Bus messages are automatically completed or abandoned by Azure Functions runtime based on the success/failure of the function call, docs:

The Functions runtime receives a message in PeekLock mode. It calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails.

So, the suggested way to Abandon your message is to throw an exception from function invocation.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • Thanks for the for reply. @Mikhail. However, I tried to throw an exception in the azure function to force exception to happen. however it still said function completed and the message is gone from the queue. – mslugx Jan 25 '18 at 21:46
  • Is it not in DLQ? – Mikhail Shilkov Jan 25 '18 at 21:47
  • @mslugx do you have the solution? I am running into the same issue – Hung Cao Jul 31 '18 at 19:07
  • @HungCao The issue is fixed, and it does abandon messages, and requeue the message automatically for processing. You might want to upgrade azure functions SDK to the newest version. – mslugx Aug 01 '18 at 19:26