使用ServiceBusTrigger时的Azure WebJob并发性

时间:2016-04-18 09:58:55

标签: azure azureservicebus azure-webjobs servicebus azure-webjobssdk

我一直使用Azure存储队列来使用QueueTrigger属性来提供WebJob。我将QueueTrigger配置为将多个项目出列以进行并发处理,如下所示:

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);
}

我更喜欢使用Service Bus。 MaxConcurrentCalls上的ServiceBusConfiguration参数是否允许相同的自动并行执行?例如:

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);            
}

我不确定MaxConcurrentCalls是否符合我的想法!

1 个答案:

答案 0 :(得分:3)

基本上是,MaxConcurrentCalls定义客户端用于处理队列的线程数量。

在不断轮询的infinte循环上调用QueueClient.OnMessage方法it starts a message pump时。 OnMessageOptions.MaxConcurrentCall设置number of concurrent calls to the callback the message pump should initiate

更多背景故事:Introducing the Event-Driven Message Programming Model for the Windows Azure Service Bus