MSMQ 仅接收来自某些客户端的消息
MSMQ receives messages only from some Clients
我有一个 WCF 服务,其中客户端应用程序可以通过 MSMQ 进行连接:
[ServiceContract(Namespace="http://example.com", SessionMode = SessionMode.NotAllowed)]
public interface IMyService
{
[OperationContract(IsOneWay = true)]
void Update(DataSet ds);
}
然后:
string queueName = ConfigurationManager.AppSettings["QueueName"];
NetMsmqBinding binding = new NetMsmqBinding("MyBinding");
if (!MessageQueue.Exists(@".\private$\" + queueName))
{
MessageQueue.Create(@".\private$\" + queueName, binding.ExactlyOnce);
}
ServiceHost msmqHost = new ServiceHost(typeof(MyService));
msmqHost.AddServiceEndpoint(typeof(IMyService), binding, "net.msmq://localhost/private/" + queueName);
具有以下配置:
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="MyBinding" durable="false" exactlyOnce="false" maxReceivedMessageSize="20000000">
<security mode="None" />
<readerQuotas maxDepth="32" maxStringContentLength="543192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="8456384" />
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="MyService" behaviorConfiguration="MsMqBehavior" />
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MsMqBehavior">
<serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50" maxConcurrentInstances="50" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我已经在使用具有相同配置的服务,在其他安装上没有问题。但是现在在新安装上我只收到来自一些客户端的消息(实际上是 9 个 - 有 31 个)。我收到的消息总是来自相同的服务器。我在任何地方都找不到错误消息(Windows 事件日志 (Client/Server)、WCF 跟踪文件),并且 MSMQ 状态在不发送消息的客户端机器上显示 "connected" .死信队列也是空的。
消息必须在 MSMQ 客户端和服务器之间的某处丢失(我停止了我的应用程序,在服务器队列上我只收到来自九个客户端的消息 - 如果我启用日记功能,行为相同)。
如有任何帮助,我们将不胜感激
更新
我使用性能计数器来监控队列。会话计数器显示 31 个会话的正确值。传入消息计数器也显示正确的值。但是,如果我停止应用程序或启用日记功能,则只有部分消息存储在队列中。
此博客条目中所述的克隆服务器会导致问题:http://blogs.msdn.com/b/johnbreakwell/archive/2007/02/06/msmq-prefers-to-be-unique.aspx
基本上它说您不能克隆启用了 MSMQ 功能的服务器。如果这样做,则必须在客户端计算机上重新安装 MSMQ 功能或更改注册表:
1.Stop the MSMQ Service
2.Delete the QMId value completely
3.Add a SysPrep DWORD (Under HKLM\Software\Microsoft\MSMQ\Parameters) and set it to 1
4.Start the MSMQ Service
我有一个 WCF 服务,其中客户端应用程序可以通过 MSMQ 进行连接:
[ServiceContract(Namespace="http://example.com", SessionMode = SessionMode.NotAllowed)]
public interface IMyService
{
[OperationContract(IsOneWay = true)]
void Update(DataSet ds);
}
然后:
string queueName = ConfigurationManager.AppSettings["QueueName"];
NetMsmqBinding binding = new NetMsmqBinding("MyBinding");
if (!MessageQueue.Exists(@".\private$\" + queueName))
{
MessageQueue.Create(@".\private$\" + queueName, binding.ExactlyOnce);
}
ServiceHost msmqHost = new ServiceHost(typeof(MyService));
msmqHost.AddServiceEndpoint(typeof(IMyService), binding, "net.msmq://localhost/private/" + queueName);
具有以下配置:
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="MyBinding" durable="false" exactlyOnce="false" maxReceivedMessageSize="20000000">
<security mode="None" />
<readerQuotas maxDepth="32" maxStringContentLength="543192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="8456384" />
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="MyService" behaviorConfiguration="MsMqBehavior" />
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MsMqBehavior">
<serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50" maxConcurrentInstances="50" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我已经在使用具有相同配置的服务,在其他安装上没有问题。但是现在在新安装上我只收到来自一些客户端的消息(实际上是 9 个 - 有 31 个)。我收到的消息总是来自相同的服务器。我在任何地方都找不到错误消息(Windows 事件日志 (Client/Server)、WCF 跟踪文件),并且 MSMQ 状态在不发送消息的客户端机器上显示 "connected" .死信队列也是空的。
消息必须在 MSMQ 客户端和服务器之间的某处丢失(我停止了我的应用程序,在服务器队列上我只收到来自九个客户端的消息 - 如果我启用日记功能,行为相同)。
如有任何帮助,我们将不胜感激
更新
我使用性能计数器来监控队列。会话计数器显示 31 个会话的正确值。传入消息计数器也显示正确的值。但是,如果我停止应用程序或启用日记功能,则只有部分消息存储在队列中。
此博客条目中所述的克隆服务器会导致问题:http://blogs.msdn.com/b/johnbreakwell/archive/2007/02/06/msmq-prefers-to-be-unique.aspx
基本上它说您不能克隆启用了 MSMQ 功能的服务器。如果这样做,则必须在客户端计算机上重新安装 MSMQ 功能或更改注册表:
1.Stop the MSMQ Service
2.Delete the QMId value completely
3.Add a SysPrep DWORD (Under HKLM\Software\Microsoft\MSMQ\Parameters) and set it to 1
4.Start the MSMQ Service