MSMQ WCF节流

问题描述

我有一个Windows服务,该服务通过WCF读取消息队列。我希望该服务先处理一条消息,然后再处理另一条消息(每个味精需要大量内存操作)。我将限制配置设置为1,但似乎没有任何作用。如果我的队列中有6条消息,则开始后需要4条消息。 我想念什么吗? 我的web.config:
  <system.serviceModel>
<client>
  <endpoint
    address=\"net.tcp://spserv30:9999/services/SPInterface\"
    binding=\"netTcpBinding\" bindingConfiguration=\"tcpspbinding\"
    contract=\"Itineris.OPM.WCFSP.ActionContracts.ISPActions\" >
  </endpoint>
</client>
<services>
  <service name=\"Itineris.OPM.MSMQProcessorV2.MSMQProcessor\" behaviorConfiguration=\"Throttled\" >
    <endpoint address=\"msmq.formatname:DIRECT=OS:localhost\\private$\\documents\" binding=\"msmqIntegrationBinding\"
              bindingConfiguration=\"MSMQProcessorBinding\" contract=\"Itineris.OPM.MSMQProcessorV2.IMSMQProcessor\" />
  </service>
</services>
<bindings>
  <netTcpBinding>
    <binding name=\"tcpspbinding\" transferMode=\"StreamedRequest\" />
  </netTcpBinding>
  <msmqIntegrationBinding>
    <binding name=\"MSMQProcessorBinding\" maxReceivedMessageSize=\"2147483647\" 
             receiveRetryCount=\"0\" retryCycleDelay=\"00:10:00\" maxRetryCycles=\"0\"
             receiveErrorHandling=\"Move\">
      <security mode=\"None\" />
    </binding>
  </msmqIntegrationBinding>


   </bindings>
 <behaviors>
      <serviceBehaviors>
        <behavior name=\"Throttled\">
          <serviceThrottling 
            maxConcurrentCalls=\"1\" 
            maxConcurrentSessions=\"1\" 
            maxConcurrentInstances=\"1\"
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
我的servicehost创建:
  protected override void OnStart(string[] args)
    {

            if (_serviceHost != null)
            {
                if (_serviceHost.State != CommunicationState.Faulted)
                    _serviceHost.Close();
                else
                    _serviceHost.Abort();
            }
            //create servicehost
            _serviceHost = new ServiceHost(typeof(MSMQProcessor));
            _serviceHost.Open();
            _serviceHost.Faulted += serviceHost_Faulted;

            // Already load configuration here so that service does not start if there is a configuration error.
            new DocumentGeneratorV2.LoadGeneratorConfigurator().Load();

            var startLog = new LogEntry {Message = \"Itineris MSMQ Processor Service V2 has started\"};
            startLog.Categories.Add(CategoryGeneral);
            startLog.Priority = PriorityNormal;

            Logger.Write(startLog);






    }

    private void serviceHost_Faulted(object sender,EventArgs e)
    {
        if (!_isClosing)
        {
            _serviceHost.Abort();
            _serviceHost = new ServiceHost(typeof(MSMQProcessor));
            _serviceHost.Faulted += serviceHost_Faulted;
            _serviceHost.Open();
        }
    }
合同课:
  [ServiceContract(Namespace = \"http://Itineris.DocxGenerator.MSMQProcessor\")]
[ServiceKnownType(typeof(string))]
public interface IMSMQProcessor

{
    [OperationContract(IsOneWay = true,Action = \"*\")]
    void GenerateWordDocument(MsmqMessage<string> message);
}

public class MSMQProcessor : IMSMQProcessor
{
    /// <summary>
    /// Method that processed the message and generates a word document
    /// </summary>
    /// <param name=\"message\">message from MSMQ to be processed</param>
    [OperationBehavior(TransactionScopeRequired = true,TransactionAutoComplete = true)]
    public void GenerateWordDocument(MsmqMessage<string> message)
    {
        DocumentGeneration documentGenerator = null;
        var state = new DocumentStatus();
        var docGenerator = new DocumentGenerator(new LoadGeneratorConfigurator().Load());


            var deserializer = new XmlSerializer(typeof(DocumentGeneration));

            documentGenerator = deserializer.Deserialize(new StringReader(message.Body)) as DocumentGeneration;
            if(documentGenerator == null)
                throw new Exception(\"Deserializing of the message has failed\");

            docGenerator.MailQueue = appSettings[\"MAILQUEUE\"];
            docGenerator.GenerateDocument(documentGenerator);


            var builder = new StringBuilder();
            builder.Append(\"The documents have been saved to the following locations: \\r\\n\");

            }
            }
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)