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:
<UnicastBusConfig> <MessageEndpointMappings> <add Messages="MyApp.Messaging.MessageType1, MyApp.Messaging" Endpoint="MyApp.Service1.InputQueue"/> <add Messages="MyApp.Messaging.MessageType2, MyApp.Messaging" Endpoint="MyApp.Service2.InputQueue"/> </MessageEndpointMappings> </UnicastBusConfig>