I'm developing an Azure Service Bus trigger function with MassTransit, and I'm getting the following error messages when the bus is injected with about 10K messages in a short time (~5 mins).
The function should read the messages coming from the bus, do a transformation, and then queue a subsequent message into another topic.
Here's the error message I'm getting:
Cannot allocate more handles. The maximum number of handles is 4999. (QuotaExceeded). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot.
Exception type: Azure.Messaging.ServiceBus.ServiceBusException
Failed method: Azure.Messaging.ServiceBus.Amqp.AmqpConnectionScope+<CreateSendingLinkAsync>d__85.MoveNext
Here's my Function App Code:
[FunctionName(nameof(HubspotWebhookCommandReceiver))]
public async Task Run([ServiceBusTrigger("%HubspotWebhook:CommandQueueName%", Connection = "ServiceBusConnection")]
ServiceBusReceivedMessage[] messages, CancellationToken cancellationToken)
{
_logger.LogInformation("Handling {count} Hubspot Webhook Commands", messages.Count());
var handles = new List<Task>();
foreach (var message in messages)
{
handles.Add(_messageReceiver.HandleConsumer<HubspotWebhookCommandConsumer>(_configuration.CommandQueueName, message, cancellationToken));
}
await Task.WhenAll(handles);
}
And the host.json file:
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensions": {
"http": {
"routePrefix": ""
},
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 16,
"maxAutoRenewDuration": "00:05:00"
},
"batchOptions": {
"maxMessageCount": 1000,
"operationTimeout": "00:01:00",
}
}
}
}
Any suggestions would be much appreciated, as I've been trying to fix the issue for a couple of days now. Thanks!
prefetchCountandmaxConcurrentCallsin yourhost.jsonto reduce the number of concurrent connections and avoid exceeding the handle limit.