Max Delivery Count with Azure Service Bus Topic Trigger RRS feed

  • Question

  • Configured service bus topic with a subscription which has MaxDeliveryCount set to 10 and DeadLetterQueue..  For the same service bus topic have created a service bus topic trigger. In the service bus topic trigger forcibly setting the exception to make the message as Abandon.

    However message is going to DeadLetterQueue without reaching MaxDeliveryCount. Service Bus Topic Trigger is not getting triggered for Abandon messages until it reaches MaxDeliveryCount. Is PeekLock behavior is not available for Service Bus Topic Trigger? 

    Code for Service Bus Topic Trigger;

    using System;
    using System.Threading.Tasks;
    public static async Task Run(string mySbMsg, Int32 DeliveryCount, string MessageId,TraceWriter log)
         log.Info($"C# Azure Service Bus Topic trigger function saved file: {mySbMsg} ");
            log.LogInformation($"DeliveryCount: {DeliveryCount}");
         await SampleFunction(log);
        catch(Exception ex)
            log.Info($"Exception: {ex} ");
            throw ;
    public static async Task SampleFunction(TraceWriter log)
    log.Info($"C# Azure Service Bus Topic trigger function SampleFunction: ");
    throw new ArgumentNullException("argument");


    Thursday, May 16, 2019 9:18 PM

All replies

  • Service Bus Queues and Subscriptions each have a QueueDescription.MaxDeliveryCount and SubscriptionDescription.MaxDeliveryCount property respectively. the default value is 10. Whenever a message has been delivered under a lock (ReceiveMode.PeekLock), but has been either explicitly abandoned or the lock has expired, the message BrokeredMessage.DeliveryCount is incremented. When DeliveryCount exceeds MaxDeliveryCount, the message is moved to the DLQ, specifying the MaxDeliveryCountExceeded reason code.

    The purpose of the dead-letter queue is to hold messages that cannot be delivered to any receiver, or messages that could not be processed. This could be due to various reasons like exceeding MaxDeliveryCount, exceeding TimeToLive, errors while processing subscription rules etc.

    The Azure 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. If the function runs longer than the PeekLock timeout, the lock is automatically renewed as long as the function is running.

    Tuesday, May 21, 2019 4:25 AM