Search code examples
nservicebus

NServiceBus Distributor/Worker ConfigurationErrorsException - 'MasterNodeConfig.Node' points to a local host name: [localhost]


I am attempting to configure a NServiceBus Distributor/Worker for development purposes. I have the following dependencies installed:

  • NServiceBus.Core v5.2.14
  • NServiceBus.Distributor.MSMQ v5.0.4
  • NServiceBus.Host v6.0.0

A ConfigurationErrorsException is thrown in one of the workers with the following message:

'MasterNodeConfig.Node' points to a local host name: [localhost]

The intent of this error is clear. A configuration pointing to localhost defeats the purpose of the distributed architecture. Although for development purposes this type of configuration is optimal. Below is the configuration of my worker:

<TransportConfig MaxRetries="5"/>

<MasterNodeConfig Node="localhost"/>
<UnicastBusConfig
  DistributorControlAddress="distributor.distributor.control@localhost"
  DistributorDataAddress="distributor@localhost">
    <MessageEndpointMappings></MessageEndpointMappings>
</UnicastBusConfig>

<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>

In the link below is a working sample :

Scale Out with the Distributor

Comparing my solution to the example in the link above it is unclear what may be causing the ConfigurationErrorsException in my worker. Any suggestions?


Solution

  • Trying to create a sample for the Distributor that can run on a single machine, which by definition is supposed to run on multiple machines, is somewhat difficult. (The sample does discuss scaling out in a real environment further down. We added a note near the top to link to it.)

    The part in the sample that isn't in your code is an appSetting:

    <appSettings>
      <add 
        key="NServiceBus/Distributor/WorkerNameToUseWhileTesting" 
        value="Samples.Scaleout.Worker1" />
    </appSettings>
    

    If this setting is present, the check for loopback addresses in the MasterNode config will be skipped. This is, unfortunately, not documented, and may exist only to make this sample work. We will investigate and resolve as part of the issue I raised.

    In real life, however, you should really use full machine names rather than localhost. That, of course, you can't do in a sample.

    Another item is that the MasterNodeConfig and the DistributorControlAddress/DistributorDataAddress attributes on UnicastBusConfig don't really go together, or don't need to.

    MasterNodeConfig is meant to be a simple way to configure all endpoints with the very same configuration file. If the endpoint is Sales and the MasterNode is ServerA, then the control address is Sales.Control@ServerA and the data address is Sales@ServerA. But that always assumes multiple machines. So the two attributes allow you to specify custom queues that may be on the same machine. Therefore, if you're using the two attributes, you really shouldn't be using MasterNodeConfig at all.