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}");
}
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With