Azure WebJob concurrency when using ServiceBusTrigger

余生颓废 提交于 2019-12-07 04:07:21

问题


I have been using Azure Storage Queues to feed a WebJob, using the QueueTrigger attribute. I configure my QueueTrigger to dequeue a number of items for concurrent processing, like this:

public static void Main()
{
    JobHostConfiguration config = new JobHostConfiguration();
    config.NameResolver = new QueueNameResolver();

    config.Queues.NewBatchThreshold = 10;

    JobHost host = new JobHost(config);
    host.RunAndBlock();
}

public static void ExecuteStorageQueueItem([QueueTrigger("%AzureQueueName%")] CloudQueueMessage message, TextWriter logger)
{
    ProcessRequest(message.AsString, logger);
}

I would prefer to use Service Bus. Does the MaxConcurrentCalls parameter on ServiceBusConfiguration allow for the same automatic parallel execution? For example:

public static void Main()
{

    JobHostConfiguration config = new JobHostConfiguration();
    config.NameResolver = new QueueNameResolver();

    ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration();
    serviceBusConfig.MessageOptions.MaxConcurrentCalls = 10;
    config.UseServiceBus(serviceBusConfig);

    JobHost host = new JobHost(config);
    host.RunAndBlock();
}

public static void ExecuteServiceBusItem([ServiceBusTrigger("%ServiceBusQueueName%")] BrokeredMessage message, TextWriter logger)
{
    ProcessRequest(message.GetBody<string>(), logger);            
}

I'm not sure whether MaxConcurrentCalls does what I think it does!


回答1:


Essentially yes, MaxConcurrentCalls defines the amount of threads used by the Client to process the queue.

When QueueClient.OnMessage method is called it starts a message pump on an infinte loop that is constantly polling. The OnMessageOptions.MaxConcurrentCall sets the number of concurrent calls to the callback the message pump should initiate.

More back story: Introducing the Event-Driven Message Programming Model for the Windows Azure Service Bus



来源:https://stackoverflow.com/questions/36690775/azure-webjob-concurrency-when-using-servicebustrigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!