I have a .NET Windows Service project deployed to an Azure App Service. My goal is to receive 100,000 messages from an Azure Service Bus queue and process these messages in a message handler. However, after processing approximately 800 messages, the service stops receiving new messages and becomes idle. How can I ensure that the Azure Service Bus continues to receive and process all 100,000 messages without stopping?
public void ReceiveMessages(string queueName, string namespaceConnectionString, string appInsightInstrumentationKey, string domainUrl, SecretClient client)
{
var clientOptions = new ServiceBusClientOptions()
{
TransportType = ServiceBusTransportType.AmqpWebSockets,
};
var serviceBusClient = new ServiceBusClient(namespaceConnectionString, clientOptions);
var adminClient = new ServiceBusAdministrationClient(namespaceConnectionString);
var processorOptions = new ServiceBusProcessorOptions
{
AutoCompleteMessages = false,
MaxAutoLockRenewalDuration = TimeSpan.FromHours(1)
};
var serviceBusProcessor = serviceBusClient.CreateProcessor(queueName, new ServiceBusProcessorOptions());
_serviceBusProcessor = serviceBusProcessor;
var handlerParams = new MessageHandlerParameter
{
AppInsightInstrumentationKey = appInsightInstrumentationKey,
DomainUrl = domainUrl,
Client = client
};
try
{
// Add handler to process messages;
serviceBusProcessor.ProcessMessageAsync += (args) => MessageHandlerAsync(args, handlerParams);
// Add handler to process any errors;
serviceBusProcessor.ProcessErrorAsync += ErrorHandlerAsync;
serviceBusProcessor.StartProcessingAsync();
Console.WriteLine("Wait sometime for processing to start");
Task.Delay(Timeout.InfiniteTimeSpan);
}
catch (Exception ex)
{
}
finally
{
_ = serviceBusProcessor.DisposeAsync();
_ = serviceBusClient.DisposeAsync();
}
}
I am expecting to receive 100k messages without stopping.
