NServiceBus - reply to a message after publication

I have a subscriber who successfully processes the message, then the subscriber successfully publishes another message to indicate that some event has occurred, my problem is that after publication I try to return the message to the sender of the initial message, and the system crashes with the following message

The destination for the NServiceBus.Unicast.Transport.CompletionMessage message is not specified. Message could not be sent. Check the UnicastBusConfig section in the configuration file and verify that MessageEndpointMapping exists for the message type.

The return code is as follows:

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

and app.config looks like this:

 <configuration> <configSections> <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core"/> </configSections> <MsmqTransportConfig InputQueue="MyServerInputQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5"/> </configuration> 

I added the unicast section and still getting the same error. I understand that NServicebus knows how to reply to a message, and I don’t need to specify a queue for a reply to go further than the MsmqTransportConfig input queue found in app.config.

Is it possible for the subscriber to post a message and then respond to the message in which the message was sent?

+4
source share
1 answer

If you use Bus.Return (), you must register the callback on the client endpoint as follows:

 Bus.Send<IRequestDataMessage>(m => { m.DataId = g; m.String = "<node>it 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 the full message of your choice, use the Bus.Reply () command and write a handler at the client endpoint. My complete sample can be found here .

+7
source

Source: https://habr.com/ru/post/1334459/


All Articles