title: NServiceBus clustered workers / Distributor usage
body: <p><img src="https://i.stack.imgur.com/RxeJJ.png" alt="Current Setup"></p>
  
  <p><strong>Current Setup</strong></p>
  
  <p>We have a UI (well more than 1 UI, but that is not relevant), and we have 2 load balanced app servers. Such the UI will talk to an alias, behind which are the 2 load balancer app servers.
  The app servers are also self hosting NServiceBus endpoints. The app server (this could be either App Server 1 or App Server 2 ) that is dealing with the current request is capable of doing the following using the self hosted NServiceBus:</p>
  
  <ul>
  <li>Send a message locally (this is a calculation that can be run at any
  time, and it doesn’t matter who triggers it, it is just a trigger to
  do the calculation) </li>
  <li>Send a command to the publisher on the Ancillary
  Service Box (the publisher pushes new event to Worker 1 and Worker 2)</li>
  <li>Send a command to Worker 1 directly on the Ancillary Services Box</li>
  <li>Send a command to Worker 2 directly on the Ancillary Services Box</li>
  </ul>
  
  <p><strong>The "App Server(s)" current App.Config</strong></p>
  
  <p>As such the App.Config for each app server has something like this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;UnicastBusConfig ForwardReceivedMessagesTo="audit"&gt;
      &lt;MessageEndpointMappings&gt;
        
        &lt;add Assembly="Messages" Type="PublisherCommand" Endpoint="Publisher" /&gt;
        &lt;add Assembly="Messages" Type=" Worker1Command" Endpoint="Worker1" /&gt;
        &lt;add Assembly="Messages" Type=" Worker2Command" Endpoint="Worker2" /&gt;
        &lt;!-- This one is sent locally only --&gt;
        &lt;add Assembly=" Messages" Type="RunCalculationCommand" Endpoint="Dealing" /&gt;
      &lt;/MessageEndpointMappings&gt;
    &lt;/UnicastBusConfig&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>The “Publisher” current  App.Config</strong></p>
  
  <p>Currently the “Publisher” App.Config </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;UnicastBusConfig ForwardReceivedMessagesTo="audit"&gt;
    &lt;MessageEndpointMappings&gt;
    &lt;/MessageEndpointMappings&gt;
  &lt;/UnicastBusConfig&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>The “Worker(s)” current  App.Config</strong></p>
  
  <p>Currently the worker App.Configs at the moment only have to subscribe to one other endpoint the “Publisher”, their config files looks like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;UnicastBusConfig ForwardReceivedMessagesTo="audit"&gt;
    &lt;MessageEndpointMappings&gt;
      &lt;add Assembly="Messages" Type="SomeEvent" Endpoint="Publisher" /&gt;
    &lt;/MessageEndpointMappings&gt;
  &lt;/UnicastBusConfig&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>All other messages to the workers right now come directly from one of the app servers, as shown in the App.Config above for the app servers.</p>
  
  <p>This is all working correctly.</p>
  
  <p>Thing is we have a single point of failure, if the “Ancillary Services Box” dies, we are stuffed.</p>
  
  <p>So we are wondering if we could make use of multiple “Ancillary Services Boxes (each with a Publishers/Worker1/Worker2)”. Ideally they would work exactly as described above, and as shown in the diagram above. Where if “Ancillary Services Box 1” is available it is used, otherwise we use “Ancillary Services Box 2”</p>
  
  <p>I have read about the distributor (but not used it), which if I have it correct, we may be able to use in either the AppServer(s) themselves, where we treat each AppServer as a Distributor and a worker (for the case where we need to do the SendLocal command (RunCalculationCommand) we need to run).</p>
  
  <p>Where the “Ancillary Services Box” would have to use the Distributor for each of the contained endpoints:</p>
  
  <p>So we may end up with something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/YZJaR.png" alt="What we may want to do"></p>
  
  <p>Could someone help me to know if I am even thinking about this the right way, or whether I am way off.</p>
  
  <p>Essentially what I want to know is:</p>
  
  <ul>
  <li>Is the distributor the correct approach to use?</li>
  <li>What would the worker / publisher configs look like, they would have to change somehow to point to distributor no? As I state right now the app servers send a message directly to the workers, to the app server config has the worker end point address, and the worker is only setup to point to the publisher</li>
  <li>What would the app servers config look like? Would this stop sending directly to the publisher / workers?</li>
  <li>What would the publisher config look like? Should this point to the distributor?</li>
  </ul>