Data distribution

Component: NServiceBus
NuGet Package NServiceBus (5.x)
Asynchronous messaging is not an optimal solution for data distribution scenarios. It is usually better to use a dedicated data distribution technology for that purpose, such as a distributed cache or distributed configuration service.

NServiceBus Publish/Subscribe mechanism always delivers events to a single instance of each logical subscriber. Sometimes, however, there is a reason for delivering each event to all instances of the subscriber in order to distribute data. While it is usually better to use a dedicated data distribution technology for that purpose (e.g. a distributed caching solution), NServiceBus can also be used in data-distribution mode.

5.2 NServiceBus
var scaleOutSettings = busConfiguration.ScaleOut();
scaleOutSettings.UniqueQueuePerEndpointInstance();

The code above instructs NServiceBus to use a unique input queue for each endpoint instance. The actual queue name is derived from the endpoint name and the Azure role instance ID. When instances of such endpoint subscribe for an event, each instance subscribes with its own unique input queue so the publisher treats each subscription individually and, as a result, broadcasts events to all subscribed instances.

In case there is a need to provide a custom queue names suffix (instead of using the role instance ID), following API can be used instead:

5.2 NServiceBus
var scaleOutSettings = busConfiguration.ScaleOut();
scaleOutSettings.UniqueQueuePerEndpointInstance("-MyCustomSuffix");

Last modified