开发者

NServiceBus - replying to message after publish

I have a subscriber that successfully handles a message, the subscriber then proceeds to successfully publish another message to state that a certain event has happened, my problem is that i after the publish i attempt to return a message to the sender of the initial message and the system fails with the following message

No destination specified for message NServiceBus.Unicast.Transport.Co开发者_JAVA百科mpletionMessage. Message cannot be sent. Check the UnicastBusConfig section in your config file and ensure that a MessageEndpointMapping exists for the message type.

The return code looks as follows:

 Bus.Publish(orderMessage);

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

and the app.config is as follows:

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

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

I've added a unicast section and still get the same error. My understanding is that NServicebus knows how to reply to the message and i shouldn't have to specify a queue for the reply to go on other than the MsmqTransportConfig input queue found in the app.config.

Is it possible to have a subscriber publish a message then respond to the where the message was sent?


If you use Bus.Return() then you must register a call back on the client endpoint like so:

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"]));

If you want to return a full message of your choosing then use Bus.Reply() and write a handler in your client endpoint. My full sample can be found here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜