Reputation: 2840
I have an Azure Function that triggers on a Session Enabled Queue, defined like this
[ServiceBusTrigger("QueueName", Connection = "ServicebusConnectionString",
IsSessionsEnabled = true)] string queueItem)
My issue is that the function is only processing messages one at a time. Because of this, it takes a lot longer to finish a session than necessary. How do I make the function process messages concurrently?
I am currently relying on default values for configuration of the trigger, I have nothing explicitly set in my host.json.
I am using the newest version of Azure Functions, with the Isolated Model: https://github.com/Azure/azure-functions-dotnet-worker
Upvotes: 1
Views: 1570
Reputation: 21
I think the other option might be using sessions + partitioned queues/topics together to speedup ordered processing
Useful docs:
https://www.youtube.com/watch?v=BmatDG4yEgI&ab_channel=CiaranO%27Donnell https://azure.microsoft.com/en-gb/blog/partitioned-service-bus-queues-and-topics/
Upvotes: 0
Reputation: 25994
My issue is that the function is only processing messages one at a time. Because of this, it takes a lot longer to finish a session than necessary. How do I make the function process messages concurrently?
That's by design. A Service Bus session can only be processed by a single consumer to ensure message ordering. If you need to process messages concurrently and OK with out-of-order processing, you could use non-session queues.
But if you're looking to speed up processing, then batching could help. The trigger will be given more than one message, rather than just a single message.
public static Task Run(
[ServiceBusTrigger("topic", "subscription", IsBatched = true)] string[] messages,
FunctionContext context)
{
// your code
}
The Isolated Worker SDK configuration shows how to configure the max.
I am not sure you can mix sessions and batches though.
Upvotes: 2