Getting the NServiceBus Distributor Working

All of this assumes that you’ve built NServiceBus in line with what I said on the previous post.  This is just enough to modify the FullDuplex sample to load balance.  Most of this has previously appeared on the yahoo groups, but I’ve just organized it for comprehension.

Step 1: Modify the configs

Amazingly, all you need to do is to modify the configs of the samples.  Here’s what you need to do.

Client

c:NSBSamplesFullDuplexClientbindebugClient.exe.config

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

Distributor

c:NSBsrcdistributorNServiceBus.Unicast.Distributor.RunnerbinDebugNServiceBus.Unicast.Distributor.Runner.exe.config

Requires no changes.  It just works.  (!)

Server 1

C:NSBSamplesFullDuplexServerbinDebugServer.exe.config

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

<
UnicastBusConfig DistributorControlAddress="distributorcontrolbus" DistributorDataAddress="distributordatabus">
<
MessageEndpointMappings>
<
add Messages="Messages" Endpoint="IGNORE" />
</
MessageEndpointMappings>
</
UnicastBusConfig>

Obviously, Endpoint “IGNORE” is never used.  I’m just setting this to emphasize that messages from the server don’t use this setting in this scenario.

Server 2

Go to C:NSBSamplesFullDuplexServerbinDebug

Copy the entire folder to C:NSBSamplesFullDuplexServerbinDebug2

Change C:NSBSamplesFullDuplexServerbinDebug2Server.exe.config

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

<
UnicastBusConfig DistributorControlAddress="distributorcontrolbus" DistributorDataAddress="distributordatabus">
<
MessageEndpointMappings>
<
add Messages="Messages" Endpoint="IGNORE" />
</
MessageEndpointMappings>
</
UnicastBusConfig>

You need to create a full copy because of the way the SpringBuilder operates.  Two servers in the same folder will fail, with an extremely unhelpful error message (Object Variable not Set, to be precise.).

Step 2: Run the system

To run it:

  • Open up four command windows
  • C:NSBsrcdistributorNServiceBus.Unicast.Distributor.RunnerbinDebugNServiceBus.Unicast.Distributor.Runner.exe
  • c:NSBSamplesFullDuplexServerbinDebugServer.exe
  • c:NSBSamplesFullDuplexServerbinDebug2Server.exe
  • c:NSBSamplesFullDuplexClientbinDebugClient.exe

You can now start servers, stop servers, watch messages queue up and recover, watch it load balance between the two. 

Step 3: See what it’s doing

If you start running parts of this system through the debugger, you’ll want to switch off some exceptions fairly quickly, since they happen all the time.

  • System.Messaging.MessageQueueException:  every time it reads from an empty queue
  • System.BadImageFormatException:  when it tries to read a config file as an assembly.  (really)

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

One thought on “Getting the NServiceBus Distributor Working”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s