简体   繁体   中英

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.CompletionMessage. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM