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"/>

Run NServiceBus generic host as 32bit process on 64bit machine September 7, 2010

Filed under: Error,NServiceBus,Systems Administration — Rupert Bates @ 3:37 pm

I recently encountered the following error when deploying a service in the NServiceBus generic host (NServiceBus.Host.exe) on a 64bit machine,

System.InvalidOperationException: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

It turns out that this is actually a symptom of a problem which can show itself in a number of ways and is caused by running a service which depends on a 32bit dll (in this case the Microsoft Jet drivers) on a 64bit system in the generic host.

To fix it you can create a version of the generic host which is configured to run as 32bit as follows:

Run a visual studio command prompt and cd to the directory where NServiceBus.Host.exe is.  You will also need the NServiceBus.snk file from the NServiceBus download in the same directory so that you can resign the assembly after configuring it

At the command prompt type:

corflags /32BIT+ /Force NServiceBus.Host.exe

sn -R NserviceBus.Host.exe NServiceBus.snk

You can now deploy this version of the host onto your 64bit server and services which use it will run in 32bit mode


DTC Error with NServiceBus and Linq To Sql August 31, 2010

Filed under: Error,Linq to Sql,NServiceBus — Rupert Bates @ 8:08 pm

I spent most of the morning debugging the following error which I got when using Linq To Sql with NServiceBus:

The transaction has already been implicitly or explicitly committed or aborted

This occurred whenever I tried to do any data access from within a service running in the NServiceBus generic host, and confused the hell out of me because I knew the same code was working fine outside of the service.

In the end I eventually tracked it down to an error with the Distributed Transaction Coordinator service which NServiceBus uses to handle transactions. By using the DTCPing tool I was able to see that while my workstation could connect to the database server the server could not then connect back to my machine.

A bit more digging revealed that this was because the DNS entry for my computer’s host name was incorrect (I sometimes have to change it to access certain sets of servers and the DNS evidently can’t keep up).  Apparently this error or one very like it can also be caused by incorrect firewall settings.

As a temporary workaround I got it working by putting the correct IP in an entry in the server’s hosts file; since this is not a situation that will happen in a production environment I’m not that concerned. I believe another solution would be to run my service AsA_Client in NServiceBus and handle the transactions myself; I will probably end up doing this as it gives me a bit more control over how the transactions are implemented.

Loving NServiceBus though…