我怎样才能让 WCF MSMQ 一次获得超过 10 条消息?
How can I get WCF MSMQ to get more then 10 messages at a time?
我已经以编程方式设置了 msmq 绑定和限制,但即使我将 MaxConcurrentCalls、MaxConcurrentSessions 和 MaxConcurrentInstances 指定为高于 10,我也无法一次处理超过 10 条消息。
这是创建主机的代码:
var host = new ServiceHost(typeof(MqProcessRequestServer));
var binding = new NetMsmqBinding(NetMsmqSecurityMode.None)
{
UseSourceJournal = true,
ReceiveErrorHandling = ReceiveErrorHandling.Drop,
ReceiveRetryCount = 0,
MaxRetryCycles = 0,
RetryCycleDelay = TimeSpan.FromMinutes(1),
ExactlyOnce = true,
Durable = true,
MaxReceivedMessageSize = 4000000000,
ReceiveTimeout = TimeSpan.FromSeconds(30)
};
var queueUri = string.Format("net.msmq://localhost/private/{0}", scriptEngineVersion);
host.AddServiceEndpoint(typeof(IMqProcessRequest), binding, queueUri);
// Set throttling to ScriptEngine.Capacity in datamodel
var throttling = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = capacity,
MaxConcurrentSessions = capacity,
MaxConcurrentInstances = capacity
};
host.Description.Behaviors.Add(throttling);
// Set service timeout
var behavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
behavior.TransactionTimeout = TimeSpan.FromSeconds(60).ToString();
这是服务行为:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall, ReleaseServiceInstanceOnTransactionComplete = false)]
public class MqProcessRequestServer : IMqProcessRequest, IDisposable
我已经尝试了不同的容量值,所有小于 10 的都可以正常工作,因为我最多配置,但超过 10 只会是 10。
您允许的 10 个连接是由 ServicePointManager.DefaultConnectionLimit
上的默认值引起的。
在该设置的 MSDN documentation 的注释部分中说:
When used in the server environment (ASP.NET) DefaultConnectionLimit defaults to higher number of connections, which is 10.
在 none 服务器环境中,默认值为 2。
为了允许在应用程序启动时设置更多连接,当应用程序域加载时,DefaultConnectionLimit。
ServicePointManager.DefaultConnectionLimit = 100;
上一行应该允许 100 个连接。
我已经以编程方式设置了 msmq 绑定和限制,但即使我将 MaxConcurrentCalls、MaxConcurrentSessions 和 MaxConcurrentInstances 指定为高于 10,我也无法一次处理超过 10 条消息。
这是创建主机的代码:
var host = new ServiceHost(typeof(MqProcessRequestServer));
var binding = new NetMsmqBinding(NetMsmqSecurityMode.None)
{
UseSourceJournal = true,
ReceiveErrorHandling = ReceiveErrorHandling.Drop,
ReceiveRetryCount = 0,
MaxRetryCycles = 0,
RetryCycleDelay = TimeSpan.FromMinutes(1),
ExactlyOnce = true,
Durable = true,
MaxReceivedMessageSize = 4000000000,
ReceiveTimeout = TimeSpan.FromSeconds(30)
};
var queueUri = string.Format("net.msmq://localhost/private/{0}", scriptEngineVersion);
host.AddServiceEndpoint(typeof(IMqProcessRequest), binding, queueUri);
// Set throttling to ScriptEngine.Capacity in datamodel
var throttling = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = capacity,
MaxConcurrentSessions = capacity,
MaxConcurrentInstances = capacity
};
host.Description.Behaviors.Add(throttling);
// Set service timeout
var behavior = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
behavior.TransactionTimeout = TimeSpan.FromSeconds(60).ToString();
这是服务行为:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall, ReleaseServiceInstanceOnTransactionComplete = false)]
public class MqProcessRequestServer : IMqProcessRequest, IDisposable
我已经尝试了不同的容量值,所有小于 10 的都可以正常工作,因为我最多配置,但超过 10 只会是 10。
您允许的 10 个连接是由 ServicePointManager.DefaultConnectionLimit
上的默认值引起的。
在该设置的 MSDN documentation 的注释部分中说:
When used in the server environment (ASP.NET) DefaultConnectionLimit defaults to higher number of connections, which is 10.
在 none 服务器环境中,默认值为 2。
为了允许在应用程序启动时设置更多连接,当应用程序域加载时,DefaultConnectionLimit。
ServicePointManager.DefaultConnectionLimit = 100;
上一行应该允许 100 个连接。