There are two main ways to set up Microsoft Message Queue Server (MSMQ) 2.0 on a Windows 2000 computer - Workgroup or Directory mode. This is determined when configuring MSMQ for the first time. To determine whether your MSMQ 2.0 is configured in Workgroup or Directory mode, check the following registry subkey: HKLM\SOFTWARE\Microsoft\MSMQ\Parameters A value named "Workgroup" with a value of 1 (0x1) indicates that MSMQ 2.0 was installed in Workgroup mode.
MSMQ有两种安装方式(Workgroup,Directory mode),两种模式的区别见底部参考链接 在win10环境下查看注册表路径:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\Parameters\Workgroup
Being part of a domain is a pre-cursor for installing MSMQ in AD-integrated mode. It doesn't guarantee MSMQ IS installed in AD-integrated mode. MSMQ will install in workgroup mode if:
- AD integration was not selected as a setup option
- AD integration was selected but failed to initialise; check event logs
如上所述,MSMQ的安装模式会默认为workgroup,不过我在安装的时候已经勾选了MSMQ节点下的所有选项,但是显示的还是workgroup模式 当我尝试使用自有代码新建、操作message queue时,会遇到如下错误:
A workgroup installation computer does not support the operation.
这表明我尝试使用AD模式下才能有的特性,比如:
公共队列必须在Active Directory模式下使用。因此是无法使用类似MessageQueue.GetPublicQueues()获取公共队列
所以如果你也是workgroup模式,发现网上或者书上例子跑不通的话,都可以尝试去操作私有的队列,这里有个操作不同类型队列的路径表还是比较有用:
队列类型 | 语法 |
---|---|
公有队列 | MachineName\QueueName |
私有队列 | MachineName\Private$\QueueName |
日志队列 | MachineName\QueueName\Journal$ |
计算机日志队列 | MachineName\Journal$ |
计算机死信队列 | MachineName\DeadLetter$ |
计算机事务死信队列 | MachineName\XactDeadLetter$ |
string path = @".\private$\MyNewPrivateQueue";
if (MessageQueue.Exists(path))
{
var queue = new MessageQueue(path);
Console.WriteLine("open existing queue");
Console.WriteLine(queue.Label);
queue.Send("Sample Message", "Label");
}
else
{
Console.WriteLine("Queue not existing");
var queue = MessageQueue.Create(path )
}
另外还可以使用Format方式打开队列
new MessageQueue(@"FormatName:Public=xxx-xx--xxx.....")
参考: Why does MSMQ think I'm on a workgroup computer?
How to determine if MSMQ 2.0 is installed in Workgroup or Directory mode
Information about Workgroup mode and about Domain mode in Microsoft Message Queuing