Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Publishing to multiple queues from NServiceBus September 9, 2010

Filed under: NServiceBus — Rupert Bates @ 3:38 pm

Something that I found a bit confusing when setting up NServiceBus, was working out how to publish to multiple queues when I have a number of different services and message types.

The project structure I have is:

MyProject.WebApp – handles config and takes commands from user

MyProject.Messaging – defines messages and has utility classes for publishing which are called by the web app

Myproject.Service1 – reads from a message queue and does something with one type of message

Myproject.Service2 – reads from a different message queue and does something with another type of message


The confusion I had was around how to configure my web app to send different types of message to the correct queue, all the documentation is there on the NServiceBus site, it’s just not that easy to apply.

It turns out the solution is actually very simple, in the config for my web app I just need to include the message type names and the assembly they appear in to map those types to the correct queue, as follows:

      <add Messages="MyApp.Messaging.MessageType1, MyApp.Messaging" Endpoint="MyApp.Service1.InputQueue"/>
      <add Messages="MyApp.Messaging.MessageType2, MyApp.Messaging" Endpoint="MyApp.Service2.InputQueue"/>

4 Responses to “Publishing to multiple queues from NServiceBus”

  1. Just a quick note regarding the terminology here:
    Don’t you mean that you “send” (bus.Send) messages to your backend services?

    • Rupert Bates Says:

      Andreas, yes strictly speaking you are correct. I was using the term publish more generally as in publish/subscribe, but in NServiceBus terms it is ‘send’

  2. seagile Says:

    This may be a stupid question, but why aren’t those services auto-subscribing with the publisher for the events of their interest? Why put the burden on the publisher where to send to? I know for a fact that I never have to put anything like that in the config of my publisher …

    • Rupert Bates Says:

      seagile, the services do handle subscribing to the events. What I am describing is configuring a number of different publishers each with their own queue NOT setting up a 1 to 1 mapping between publisher and subscriber.

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 )

Google photo

You are commenting using your Google 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