gpt4 book ai didi

c# - NServiceBus - 发布后回复消息

转载 作者:太空狗 更新时间:2023-10-30 00:45:53 25 4
gpt4 key购买 nike

我有一个成功处理消息的订阅者,然后订阅者继续成功发布另一条消息以声明某个事件已经发生,我的问题是我在发布后尝试将消息返回给发送者初始消息和系统失败并显示以下消息

No destination specified for message NServiceBus.Unicast.Transport.CompletionMessage. Message cannot be sent. Check the UnicastBusConfig section in your config file and ensure that a MessageEndpointMapping exists for the message type.

返回码如下所示:

 Bus.Publish(orderMessage);

Bus.Return((int)MySendBus.Core.ErrorCode.Ok);

app.config 如下:

<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/>
</configSections>

<MsmqTransportConfig InputQueue="MyServerInputQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/>
</configuration>

我已经添加了一个单播部分,但仍然出现同样的错误。我的理解是 NServicebus 知道如何回复消息,除了在 app.config 中找到的 MsmqTransportConfig 输入队列之外,我不必指定一个队列来继续回复。

是否可以让订阅者发布消息然后回复消息发送的位置?

最佳答案

如果您使用 Bus.Return(),那么您必须像这样在客户端端点上注册一个回调:

Bus.Send<IRequestDataMessage>(m =>
{
m.DataId = g;
m.String = "<node>it's my \"node\" & i like it<node>";
})
.Register(i => Console.Out.WriteLine(
"Response with header 'Test' = {0}, 1 = {1}, 2 = {2}.",
Bus.CurrentMessageContext.Headers["Test"],
Bus.CurrentMessageContext.Headers["1"],
Bus.CurrentMessageContext.Headers["2"]));

如果您想返回您选择的完整消息,请使用 Bus.Reply() 并在您的客户端端点中编写一个处理程序。可以找到我的完整样本 here .

关于c# - NServiceBus - 发布后回复消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4611985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com