6

Why does the serviceBus triggers the same message multiple times? The same triggers get executed by the same message on the service bus:

[FunctionName("ProcessOrderFromServiceBusQueue")]
        public static void RunQueueMessages(
            [ServiceBusTrigger("orderqueue", Connection = "ServiceBusConnectionString")]
            string myQueueItem,
            int deliveryCount,
            DateTime enqueuedTimeUtc,
            string messageId,
            long sequenceNumber,
            TraceWriter log, ExecutionContext context)
        {
            log.Info($"C# ServiceBus Queue trigger function processed message: {myQueueItem}");            

            var config = new ConfigurationBuilder()
                                .SetBasePath(context.FunctionAppDirectory)
                                .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                                .AddEnvironmentVariables()
                                .Build();

            //var conn = config["ServiceBusConnectionString"];
            //var queueName = config["QueueName"];
            //var queueClient = new QueueClient(conn, queueName);
            //queueClient.CompleteAsync()
            log.Info($"Received Order: OrderId:{messageId} SequenceNumber:{sequenceNumber} Body:{myQueueItem}");


            // Deserialize the message body
            var order = JsonConvert.DeserializeObject<Order>(myQueueItem);

            // Process the order
            ProcessOrder(order, log, config);

            log.Info($"C# ServiceBus queue trigger function processed message: {messageId}");
        }
user3609351
  • 169
  • 1
  • 10
  • 1
    The Service Bus sevice will **never** give you the same message twice unless lock on the message was lost. Do you specify any Service Bus configurations for the Functions SDK (outside of this specific function)? What's the lock duration on this queue? – Sean Feldman Jun 08 '18 at 21:32
  • @seanFeldman the lockDuration is 30 seconds but the "autoRenewTimeout": "00:05:00" (host.json) is set on 5 min. Is the autoRenewTimeout not working? – user3609351 Jun 10 '18 at 12:07
  • Auto-renewal is not a guaranteed operation and can fail, leading to message re-appear on the queue and re-processing. Rather set `MaxLockDuration` to 5 minutes and disable automatic renewal. – Sean Feldman Jun 10 '18 at 14:57

1 Answers1

2

Most probably the body of your function throws exception during message processing. Function App aborts its processing, the message returns to the queue and immediately gets dispatched again, just to fail again and so on.

In the end, it hits Max Delivery Count and is parked in Dead Letter queue.

Could you check my hypothesis? E.g. print deliveryCount too, and check what's in DLQ.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107