【问题标题】:Nservicebus synchronous callNservicebus 同步调用
【发布时间】:2010-10-26 12:43:08
【问题描述】:

我正在为我的一个项目使用 NServiceBUs 的请求回复模型。有一个自托管服务总线侦听请求消息并回复请求消息。 所以在 WCF 消息代码中,我已经像

// 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 que 将发送回复。 在没有回复客户的情况下,我收到一两次回复。我做错什么了吗

【问题讨论】:

标签: nservicebus


【解决方案1】:

您为什么要尝试将异步框架转变为同步框架?您正在尝试做的事情存在一个根本缺陷。

您应该仔细审视您的设计,并欣赏异步调用的好处。你正在做的事实

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

高度关注。你想用这个来达到什么目的?基于异步消息通信设计您的系统,您将拥有一个更好的系统。否则你还不如只使用某种阻塞 tcp/ip 套接字。

【讨论】:

  • 否决不是答案。如果 NServiceBus 不支持它,那么就说它不支持它,并可能提供可能的原因,然后可能是一个意见。这个“答案”纯粹是一种意见(无论是不是最佳实践,还是警告、分歧、选项等)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-04
  • 1970-01-01
  • 2016-03-24
  • 1970-01-01
  • 1970-01-01
  • 2014-01-03
相关资源
最近更新 更多