MSMQ Messages Got Stuck

1 minute read

During my recent work on a project that involves NServiceBus messaging over MSMQ I got a strange issue when messages were not getting through from VMWare virtual machine to my physical PC. It started to happen when the virtual machine was placed to a domain.

The issue was that messages went fine from the physical machine to virtual machine but not the other way around. Also on the virtual machine when I look at the messaging queues I saw that all messages are “unacknowledged” in the outgoing queue.

Apparently this was something to do with the fact that this machine went to the domain and changed its name. After some hours spent trying to fix this issue, I found this handy article about MSMQ cache Id:

When I complete these registry fixes, messages started to flow and I got no unacknowledged messages in the outgoing queue.

In short, what needs to be done:

<ol><li>Stop MSMQ (Message Queuing) service</li><li>Delete the registry key HKLM\Software\Microsoft\MSMQ\Parameters\Machine Cache\QMId</li><li>Create a new DWORD called SysPrep under HKLM\Software\Microsoft\MSMQ\Parameters and set it to 1</li><li>Start MSMQ</li></ol><div>However after some testing I found that messages still come to unacknowledged state sometimes. I realized that link to the remote order_queue is created not using the remote machine name but IP address instead. This is because my VMWare VM was using NAT and communicated to a server on the host machine, that had the domain name and IP address but also NAT default router IP address. My guess was that this somehow influences MSMQ since it doesn’t understand that these two endpoints are in fact one machine. So I switched my VM to use bridged network adapter instead of the NAT virtual networks and voilà, everything works smoothly from that moment.</div>