2010-10-18 79 views
0

我正在为我的项目之一使用NServiceBUs的请求答复模型。有一个自己托管的服务总线监听请求消息并回复请求消息。 所以在WCF消息的代码,我编码方式类似于Nservicebus同步呼叫

// sent the message to bus. 
var synchronousMessageSent = 
    this._bus.Send(destinationQueueName, requestMessage) 
    .Register(
     (AsyncCallback)delegate(IAsyncResult ar) 
     { 
      // process the response from the message. 
      NServiceBus.CompletionResult completionResult = ar.AsyncState as NServiceBus.CompletionResult; 
      if (completionResult != null) 
      { 
       // set the response messages. 
       response = completionResult.Messages; 
      }              
     }, 
     null); 

     // block the current thread. 
     synchronousMessageSent.AsyncWaitHandle.WaitOne(1000); 
     return response; 

的destinaton阙将发送的答复。 我得到的答复不是来自客户端的resault one或tweo times afetr。我做错了什么

+0

想一想:http://stackoverflow.com/questions/3758405/nservice-bus-message-delay-problem – mynkow 2010-10-18 18:31:14

回答

3

你为什么要把一个同步框架变成一个同步框架?你想要做的事情有一个根本的缺陷。

您应该花很长时间仔细研究您的设计,并体会到同步呼叫的好处。你这样做的事实

// block the current thread. 
synchronousMessageSent.AsyncWaitHandle.WaitOne(1000); 

高度关注。你想用这个做什么?基于同步消息传递通信设计您的系统,您将拥有更好的系统。否则,你可能只是使用某种阻塞的TCP/IP套接字。

+0

Downvoted没有答案。如果NServiceBus不支持它,那么说它不支持它,也许提供为什么可能是,然后可能是一个意见。这个“答案”纯粹是一种观点(不管它是否是最佳做法,或警告,不同意,选择等) – Sinaesthetic 2016-11-29 19:57:33