Clarification needed on "outside message handlers" sending approach

sendonly

(Yuri M) #1

In NServiceBus 5 in order to send messages in “outside message handlers” applications like ASP.NET we used to declare IBus interface and implementation of IConfigurationSource with message type to endpoint mappings list.

In ver.6 though endpoint needs to be explicitly created (https://docs.particular.net/nservicebus/messaging/send-a-message):

var endpointConfiguration = new EndpointConfiguration(“EndpointName”);
var endpointInstance = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);

First of all, could someone please explain me the idea behind creating endpoint in order to just send messages out? I’m confused as I was under impression that endpoint is something intended to listen for messages, not to send.

Second question is what should I set for endpoint name in the example? I need to use it in send-only asp.net application to send messages to multiple endpoints. Any name?

Thanks


(Brandon Ording) #2

Hi Yuri,

For both NServiceBus 5 and 6, if you only need to send messages and don’t need to receive them, then you should create a send-only bus/endpoint:

https://docs.particular.net/nservicebus/hosting/?version=core_5#self-hosting-send-only-hosting
https://docs.particular.net/nservicebus/hosting/?version=core_6#self-hosting-send-only-hosting

For NServiceBus 6, you do need to provide an endpoint name to create the EndpointConfiguration. I recommend setting it to something that aligns with the purpose of the messages being sent.

Hope this helps!
Brandon


(Yuri M) #3

Hi Brandon,

If I sending multiple messages to multiple ‘target’ endpoints, I can create one single ‘source’ endpoint for that and send all the messages from it, right?

More over, it could be a singleton and live while mvc web application is alive, correct? If we use nested containers per http request, would it be better to let ‘source’ endpoint live per request, not per whole we application?


(Daniel Marbach) #4

Hi Yuri,

Yes you can have one send-only source endpoint that sends to multiple destinations.

Correct it can be a singleton. Scoping per request would be quite inefficient because you’d recreate the endpoint per request. The endpoint instance is thread safe and once initialized can be used over multiple web requests.

Regards
Daniel