我一直使用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
是否符合我的想法!
答案 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