Nservicebus 通用主机中的同步发送/应答
我正在尝试使用通用主机windows服务的处理程序函数的同步发送/回复,如下所示。但我认为NServiceBus只有在当前事务完成期间完成handle函数后才会发送消息。所以下面的代码将挂在“synchronousHandle.AsynchWaitHandle.WaitOne”中 这里最好的方法是什么?你能指引我Nservicebus 通用主机中的同步发送/应答,nservicebus,Nservicebus,我正在尝试使用通用主机windows服务的处理程序函数的同步发送/回复,如下所示。但我认为NServiceBus只有在当前事务完成期间完成handle函数后才会发送消息。所以下面的代码将挂在“synchronousHandle.AsynchWaitHandle.WaitOne”中 这里最好的方法是什么?你能指引我 Handler constructer ConstructorFunction(bus) { Bus = bus
Handler constructer
ConstructorFunction(bus)
{
Bus = bus
}
code in the handle function.
// sent the message to the bus and wait for the reply
IMessage response = null;
var synchronousHandle = Bus.Send(service2queue, requestMessage)
.Register(
(AsyncCallback)delegate(IAsyncResult asyncResult)
{
// Callback block for reply message
// Reply message received
NServiceBus.CompletionResult completionResult = asyncResult.AsyncState as NServiceBus.CompletionResult;
if (completionResult != null && completionResult.Messages.Length > 0)
{
// Always expecting one IMessage as reply
response = completionResult.Messages[0];
}
},
null);
// block the current thread till the reply received.
synchronousHandle.AsyncWaitHandle.WaitOne();
谢谢,
阿贾伊
nservicebus试图在不应该做的事情上尽可能让事情变得困难
从nservicebus文档中:
Bus.Send(request).Register(asyncCallback, state)
Callback only fires on first response, then is cleaned up to prevent memory leaks.
Doesn’t survive restarts – not suitable for server-side
假设您是服务器端的,我在这里猜测,因为您向我们展示了一个messagehandler,我正在考虑重新设计
service1 gets a notification about messageA
service1 sends message requestMessage to service2
service2 replies with message responseMessage to service1
service1 handles responseMessage and continues processing
如果要在继续处理之前等待service1中的多条消息,请尝试实施sagas。
nservicebus试图在不应该做的事情上尽可能让事情变得困难
从nservicebus文档中:
Bus.Send(request).Register(asyncCallback, state)
Callback only fires on first response, then is cleaned up to prevent memory leaks.
Doesn’t survive restarts – not suitable for server-side
假设您是服务器端的,我在这里猜测,因为您向我们展示了一个messagehandler,我正在考虑重新设计
service1 gets a notification about messageA
service1 sends message requestMessage to service2
service2 replies with message responseMessage to service1
service1 handles responseMessage and continues processing
如果要在继续处理之前等待service1中的多条消息,请尝试实施sagas。Duplicate:。正如您在提出的另一个问题中提到的,为什么要尝试将a-sync框架转换为同步框架?如果您想要同步调用及其引起的问题,只需使用远程处理或其他方式?如果将调用转为同步,则不会获得nservicebus的任何好处。重复:。正如您在提出的另一个问题中提到的,为什么要尝试将a-sync框架转换为同步框架?如果您想要同步调用及其引起的问题,只需使用远程处理或其他方式?如果将调用转为同步,则不会从nservicebus中获得任何好处。