Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function ServiceBusTrigger triggers multiple times the same message within milliseconds without the first finishing

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}");
        }
like image 714
user3609351 Avatar asked Jun 08 '18 18:06

user3609351


People also ask

Can Azure functions have multiple triggers?

There are no plans to support multiple triggers per Function. You will have to create a Function for each EventHub. If there is common code that may be shared between Functions, you may move them to a helper method that can be called from each Function.

How many triggers can an azure function have?

Note that because any Azure Function can have exactly only one trigger as specified, the trigger type you intend to use is what differentiates your Azure Functions when you create them in Visual Studio, so let's take a look at that.

What is azure trigger?

Triggers are what cause a function to run. A trigger defines how a function is invoked and a function must have exactly one trigger. Triggers have associated data, which is often provided as the payload of the function.


1 Answers

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.

like image 125
Mikhail Shilkov Avatar answered Oct 22 '22 04:10

Mikhail Shilkov