c a n d l a n d . n e t

NServiceBus Distributor Overview

Dusty Candland | |

Overview

The client sends messages to the distributors input queue on a remote machine. The server (or receiver) contacts the distributor asking for messages. As messages are sent to the distributor, it looks up the message endpoint in its configuration and sends the message to one of the servers waiting for work. It won’t send more to that server until it calls back to the distributor asking for more work. This stops those servers from ending up with a ton of unprocessed messages. Ayende has a good review of the Distributor here. The Colour Coding blog and this post on the Mailing list have more information about getting the samples working.

Client

The client configures the Message to go to the distributor data bus. This will be a remote queue in a distributed system.

  <MsmqTransportConfig
    InputQueue="client"
    ErrorQueue="error"
    NumberOfWorkerThreads="1"
    MaxRetries="5"
  />

  <UnicastBusConfig
      DistributorControlAddress=""
      DistributorDataAddress="">
    <MessageEndpointMappings>
      <add Messages="Messages" Endpoint="distributordatabus@xxxxxx0032" />
    </MessageEndpointMappings>
  </UnicastBusConfig>

Server

The server configures the Distributor control and data addresses on the UnicastBusConfig.

  <MsmqTransportConfig
    InputQueue="messagebus"
    ErrorQueue="error"
    NumberOfWorkerThreads="1"
    MaxRetries="5"
  />

  <UnicastBusConfig
      DistributorControlAddress="distributorcontrolbus@xxxxxx0032"
      DistributorDataAddress="distributordatabus@xxxxxx0032">
    <MessageEndpointMappings>
    </MessageEndpointMappings>
  </UnicastBusConfig>

Distributor

This distributor using the distributor control bus for it’s input. Thd distributor data bus in setup in the appSettings along with the distributor storage queue. The UnicastBusConfig need to have the message objects it will receive with the input queue of the server, messagebus in this case. This value should not be a remote value as the server will contact the distributor asking for work. It’s important for the DistributorControlAddress and DistributorDataAddress to be empty otherwise the Distributor will be in an endless loop sending stuff to itself. It would seem that the distributor would know which workers can handle which messages, but it seems like that is not the case. In other words, if you want the server to be a client in some cases with the client being the server in those cases, you need to setup another distributor. It helps to think of the Distributor as the Distributor for a specific service. Like the Business Process 1 Distributor.

  <MsmqTransportConfig
      InputQueue="distributorControlBus"
      ErrorQueue="error"
      NumberOfWorkerThreads="1"
      MaxRetries="5"
  />

  <UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="">
    <MessageEndpointMappings>
      <add Messages="Messages" Endpoint="messagebus" />
    </MessageEndpointMappings>
  </UnicastBusConfig>

  <appSettings>
    <add key="DataInputQueue" value="distributorDataBus"/>
    <add key="NumberOfWorkerThreads" value="1"/>
    <add key="ErrorQueue" value="error"/>
    <add key="StorageQueue" value="distributorStorage"/>
    <add key="NameSpace" value="http://www.UdiDahan.com"/> <!&mdash; relevant for a Serialization of "interfaces" or "xml" &mdash;>
    <add key="Serialization" value="xml"/> <!&mdash; can be either "xml", or "binary" &mdash;>
  </appSettings>

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: