2010-10-18 82 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