WCF服务侦听器到MSMQ-待处理消息 [英] WCF Service Listener to MSMQ - Pending Messages

查看:83
本文介绍了WCF服务侦听器到MSMQ-待处理消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个WCF服务,该服务侦听私有MSMQ的作业.我限制了我的服务,以使其一次只能处理一项工作(maxConcurrentInstances = 1).我的问题是,当提交两条消息并且我通过计算机管理控制台检查队列时,它是空的.我希望会有一个待处理的消息.当我提交三封邮件时,我将在MSMQ中看到一封待处理邮件.从阅读MSDN来看,似乎ServiceHost正在将下一个作业保留在内存中,直到完成当前作业为止,但是我找不到关闭它的方式,以便它不会将消息保留在内存中.有谁知道一种使之成为ServiceHost的方法,以使ServiceHost不会将待处理的消息保存在内存中并将其留在队列中?谢谢!

I've created a WCF service that listens to a private MSMQ for jobs. I've throttled my service so that it will only handle one job at a time (maxConcurrentInstances = 1). The problem I have is that when two messages are submitted and I inspect the queue through my Computer Management console, it's empty. I expect there to be one pending message. When I submit three messages, I'll see one pending message in the MSMQ. From reading MSDN, it looks like the ServiceHost is holding the next job in memory until the current job is done, but I can't find a way to turn it off so that the it doesn't hold the message in memory. Does anyone know of a way to make it so that the ServiceHost won't hold the pending message in memory and leave it in the queue? Thanks!

  <configuration>
  <system.serviceModel>
    <services>
      <service
          name="MyService"
          behaviorConfiguration="DefaultServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/MyService/"/>
          </baseAddresses>
        </host>
        <endpoint 
                  address="net.msmq://localhost/private/MyService"
                  binding="netMsmqBinding" bindingConfiguration="MsmqBindingNoSecurity"
                  contract="IMyService" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceThrottling 
            maxConcurrentCalls="1"
            maxConcurrentSessions="1"
            maxConcurrentInstances="1"
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <netMsmqBinding>
        <binding name="MsmqBindingNoSecurity"
             useActiveDirectory="false"
             exactlyOnce="false">
          <security mode="None">
            <transport
               msmqAuthenticationMode="None"/>
          </security>
        </binding>
      </netMsmqBinding>
    </bindings>

  </system.serviceModel>
</configuration>

推荐答案

我还注意到netMsmqBinding中的这种行为,据我所知,它无法从服务端进行寻址.

I have also noticed this behaviour in netMsmqBinding and as far as I know it's not addressable from the service end.

这仅是一个问题,如果您不使用事务性队列,则服务中的故障可能导致内存中消息被永久删除.

This is only an issue if you're not using transactional queues whereby a failure in your service could result in the in-memory message being dropped permanently.

即使使用事务性队列,即使已从入站队列中读取了该消息,该消息实际上仍在队列中(但它变为不可见").如果这时您的服务失败,则该消息将重新排队,然后在恢复时进行处理.

If you use transactional queues even though the message has been read from the inbound queue it's actually still there on the queue (but it becomes "invisible"). If you suffer a failure on your service at this time the message will become re-queued and then processed when you come back up.

如果不能使用事务排队,那么解决此问题的唯一方法是从客户端进行,这意味着在进行另一个呼叫之前先检查是否已发送消息.可以使用System.Messaging完成此操作,或者我认为您可以将其烘焙为自定义行为.

If you cannot use transactional queueing then the only way you can address this is to do so from the client, which means checking to see if a message has been transmitted before making another call. This can be done using System.Messaging or I assume you could bake this into a custom behaviour.

这篇关于WCF服务侦听器到MSMQ-待处理消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆