9

How does the poison-message handling work for Azure WebJobs SDK's ServiceBusTrigger ? I am looking to push the service bus queue messages that have been dequeued more than 'x' times to a different ServiceBus (or) Storage queue

The online documentation here and here and SDK Samples from here does not have examples on how the poison message handling works for ServiceBusTrigger. Is this work in progress?

I tried implementing a custom poison message handling using dequeueCount parameter but it doesn't look that it is supported for ServiceBusTriggers as I was getting a runtime exception {"Cannot bind parameter 'dequeueCount' when using this trigger."}

public static void ProcessMessage([ServiceBusTrigger(topicName: "abc", subscriptionName: "abc.gdp")] NotificationMessage message,
            [Blob("rox/{PayloadId}", FileAccess.Read)] Stream blobInput, Int32 dequeueCount)
        {
            throw new ArgumentNullException();
        }
abatishchev
  • 98,240
  • 88
  • 296
  • 433
infinity
  • 1,900
  • 4
  • 29
  • 48

3 Answers3

8

While you cannot get the dequeueCount property for ServiceBus messages, you can always bind to BrokeredMessage instead of NotificationMessage and get the property from it.

Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103
7

It looks like WebJobs handles this internally at the moment.

Reference: How to use Azure Service Bus with the WebJobs SDK

Specific section:

How ServicebusTrigger works

The SDK receives a message in PeekLock mode and calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails. If the function runs longer than the PeekLock timeout, the lock is automatically renewed.

Service Bus does its own poison queue handling, so that is neither controlled by, nor configurable in, the WebJobs SDK.

Additional Reference

Poison message handling can't be controlled or configured in Azure Functions. Service Bus handles poison messages itself.

StuartLC
  • 104,537
  • 17
  • 209
  • 285
Brendan Green
  • 11,676
  • 5
  • 44
  • 76
  • I find the ServiceBusTrigger to be...intriguing. If I check the status for the Function invocation in the WebJobs "dashboard", it says status "Success" with running time in milliseconds for an invocation that hasn't finished yet. It's a long running process (> 10 minutes), yet the status is "Success" immediately. Does the ServiceBusTrigger return success immediately and then handles the message? – Anton Oct 07 '15 at 08:07
2

To add to Brendan Green's answer, the WebJobs SDK calls Abandon on messages that failed to process, and after maximum number of retries these messages are moved to the dead letter queue by the Service Bus. The properties defining when a message will be moved into the dead letter queue, such as maximum delivery count, time to live, and PeekLock duration can be changed in Service Bus -> Queue -> Properties.

You can find more information on SB dead letter queue here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues

DivineOps
  • 1,656
  • 16
  • 17