1
我已經以編程方式設置了msmq綁定和限制,但即使我指定MaxConcurrentCalls,MaxConcurrentSessions和MaxConcurrentInstances高於10,我也無法一次處理超過10條消息。如何讓WCF MSMQ每次獲得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個。