1

我创建一个视窗形式的程序监听一个天青服务总线队列异步处理消息,并将其执行接收的每个一个漫长的过程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分钟后)处理。我想要的是这些消息被并行处理。

是否可以并行处理队列消息?

回答

2

在你OnMessageOptions例如,你需要增加你的MaxConcurrentCalls。以下代码将并行处理队列中的5条消息。

// Configure the callback options 
OnMessageOptions options = new OnMessageOptions(); 
options.AutoComplete = false; 
options.MaxConcurrentCalls = 5; 
options.AutoRenewTimeout = TimeSpan.FromMinutes(1); 
+0

非常感谢! – user1018697

相关问题