【问题标题】:How can I get WCF MSMQ to get more then 10 messages at a time?如何让 WCF MSMQ 一次获取超过 10 条消息?
【发布时间】:2016-11-17 15:30:18
【问题描述】:

我以编程方式设置了 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。

【问题讨论】:

    标签: .net wcf msmq


    【解决方案1】:

    您允许的 10 个连接是由 ServicePointManager.DefaultConnectionLimit 上的默认设置引起的。

    在该设置的 MSDN documentation 的注释部分中,它说:

    在服务器环境(ASP.NET)中使用时,DefaultConnectionLimit 默认为更高的连接数,即 10。

    在无服务器环境中,默认值为 2。

    为了允许在应用程序启动时设置更多连接,当 appdomain 加载时,DefaultConnectionLimit。

    ServicePointManager.DefaultConnectionLimit = 100; 
    

    上面的行应该允许 100 个连接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-16
      • 2018-01-03
      • 2012-08-26
      • 1970-01-01
      • 2023-03-15
      • 2019-08-04
      • 1970-01-01
      • 2021-05-22
      相关资源
      最近更新 更多