【发布时间】:2015-12-23 18:16:31
【问题描述】:
我创建了一个在 Azure 服务总线队列上侦听的 Windows 窗体程序,它为每个接收到的 brokeredMessage 执行一个漫长的过程:
QueueClient Client = QueueClient.CreateFromConnectionString(ConfigurationWrapper.QueueConnectionString, ConfigurationWrapper.QueueName);
// Configure the callback options
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromMinutes(1);
// Callback to handle received messages
Client.OnMessageAsync((message) =>
{
message.Complete();
//big jobs put 10 minutes
Task t = Task.Factory.StartNew(() => DoAVeryLongJob(message));
return t;
}, options);
如果我在此队列中以 2 秒的间隔发送 2 条消息,程序将处理第一条消息(调用 DoAVeryLongJob,需要 10 分钟),第二条消息将在第一次调用结束时处理(10 分钟后)。我想要的是并行处理这些消息。
是否可以并行处理队列消息?
【问题讨论】:
标签: c# multithreading azure message-queue azure-servicebus-queues