J.Doe
J.Doe

Reputation: 155

Using several NServicebus endpoints

I am trying to host 2 endpoints of NServicebus, pointing to 2 different queues and to send the messages to these 2 queues. For some strange reason it does not work. I googled and in some places people say that it's possible, in the other places: not possible.

Here's my code which is fine with the single endpoint:

//Here I configure the endpoint
var endpointConfiguration = new EndpointConfiguration(endpointName: Queue1);

endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.UseSerialization<JsonSerializer>();

endpointConfiguration.EnableInstallers();

endpointConfiguration.UsePersistence<InMemoryPersistence>();

_endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
//Here I send a command
_endpointInstance.Send(Queue1, command);

But the app crushes if I copy-paste this code using another variable for the new endpoint, for example _endpointInstance2 (means: I use the same code to instantiate a new endpoint)

Upvotes: 1

Views: 285

Answers (1)

Hadi Eskandari
Hadi Eskandari

Reputation: 26444

In v4 and prior you could not host more than one endpoint in an AppDomain. This was rectified in v5 and after. This sample on the documentation website shows exactly what you're looking for.

Just two things to consider: Make sure you're using the right version (you seem to be using v6 which is fine) and don't reuse the configuration object.

Upvotes: 1

Related Questions