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.
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?
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:
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.
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?
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.