在WCF MSMQ 4.0中读取自定义DLQ的服务 [英] Service for reading custom DLQ in WCF MSMQ 4.0

查看:70
本文介绍了在WCF MSMQ 4.0中读取自定义DLQ的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想编写可从DLQ中读取消息的Web服务.

Hi folks, i want to write the web service that will be read messages from DLQ.

  据我了解,如果无法将消息从客户端传递到服务(还有其他情况,例如超时,身份验证等),则消息将被放置到DLQ(在这种情况下,我使用自定义DLQ ),并且DLQ服务将被自动调用. 我编写了3个服务:客户端,服务和DLQ服务,但是当我关闭服务(服务器)并进行客户端调用服务时,则消息未放置到DLQ(在DLQ服务中未调用的适当方法).但是当我打开服务消息时 交付使用.

  As i understand if the message can not be delivered(there are other cases such as timeout, authentication etc.) from Client to Service, then message will be placed to DLQ(in this case i use custom DLQ), and DLQ Service will be called automatically.  I wrote the 3 services: client, service and DLQ Service, but  when i turn off the service(server) and make client calling service, then message is not placed to DLQ(appropriate methods not called in DLQ Service). But when i turn on service messages are delivered to service.

 我的下面的代码: 

 My code below : 

//服务器app.config 

// server app.config 

<?xml version ="1.0" encoding ="utf-8" ?>

<?xml version="1.0" encoding="utf-8" ?>

<配置>

<configuration>

 < system.web>

  <system.web>

    < compilation debug =" true" />

    <compilation debug="true" />

 </system.web>

  </system.web>

 <!-部署服务库项目时,必须将配置文件的内容添加到主机的 

  <!-- When deploying the service library project, the content of the config file must be added to the host's 

  app.config文件. System.Configuration不支持库的配置文件. ->

  app.config file. System.Configuration does not support config files for libraries. -->

 < system.serviceModel>

  <system.serviceModel>

    <服务>

    <services>

      <服务名称=" Service.MyService" behaviorConfiguration =" Service.Service1Behavior">

      <service name="Service.MyService" behaviorConfiguration="Service.Service1Behavior">

        < host>

        <host>

          < baseAddresses>

          <baseAddresses>

            < add baseAddress ="http://localhost:8731/Design_Time_Addresses/Service/MyService/" />

            <add baseAddress = "http://localhost:8731/Design_Time_Addresses/Service/MyService/" />

          </baseAddresses>

          </baseAddresses>

        </host>

        </host>

        <端点地址=" net.msmq://localhost/private/MyServiceQueue"

        <endpoint address ="net.msmq://localhost/private/MyServiceQueue"

  binding ="netMsmqBinding"

 binding="netMsmqBinding"

  contract ="Service.IMyService"

 contract="Service.IMyService"

  bindingConfiguration ="NoMSMQSecurity">

 bindingConfiguration = "NoMSMQSecurity">

          < identity>

          <identity>

            < dns value =本地主机"/>

            <dns value="localhost"/>

          </identity>

          </identity>

        </endpoint>

        </endpoint>

  <端点地址="mex"; binding ="mexHttpBinding" contract ="IMetadataExchange"/>

   <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

      </service>

      </service>

    </services>

    </services>

   < bindings>

   <bindings>

< netMsmqBinding>

<netMsmqBinding>

<绑定名称="NoMSMQSecurity">

<binding name = "NoMSMQSecurity">

<安全模式=无">

<security mode = "None">

</security>

</security>

</binding>

</binding>

</netMsmqBinding>

</netMsmqBinding>

</bindings>

</bindings>

   <行为>

   <behaviors>

    < serviceBehaviors>

    <serviceBehaviors>

      <行为名称=" Service.Service1Behavior">

      <behavior name="Service.Service1Behavior">

        < serviceMetadata httpGetEnabled ="True"/>

        <serviceMetadata httpGetEnabled="True"/>

        < serviceDebug includeExceptionDetailInFaults =" False" />

        <serviceDebug includeExceptionDetailInFaults="False" />

      </行为>

      </behavior>

    </serviceBehaviors>

    </serviceBehaviors>

   </行为>

   </behaviors>

 </system.serviceModel>

  </system.serviceModel>

</configuration>

</configuration>

 

//服务器代码

命名空间服务

{

     [ServiceContract]

    [ServiceContract]

    公共接口IMyService

    public interface IMyService

     {

    {

         [OperationContract(IsOneWay = true)]

        [OperationContract(IsOneWay = true)]

         void GetData(int value);

        void GetData(int value);

    }

    }

}

命名空间服务

{

     [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

    公共类MyService:IMyService

    public class MyService : IMyService

     {

    {

         [OperationBehavior(TransactionScopeRequired = true)]

        [OperationBehavior(TransactionScopeRequired = true)]

         public void GetData(int value)

        public void GetData(int value)

         {

        {

             tst =值;

            tst = value;

            交易交易= Transaction.Current;

            Transaction transaction = Transaction.Current;

        }

        }

         private static int tst = 0;

        private static int tst = 0;

    }

    }

}

 

//客户端app.config

//client app.config

<?xml version ="1.0" encoding ="utf-8" ?>

<?xml version="1.0" encoding="utf-8" ?>

<配置>

<configuration>

    < system.serviceModel>

    <system.serviceModel>

        < bindings>

        <bindings>

            < netMsmqBinding>

            <netMsmqBinding>

                < binding name =" NetMsmqBinding_IMyService" closeTimeout ="00:01:00"

                <binding name="NetMsmqBinding_IMyService" closeTimeout="00:01:00"

                     openTimeout =" 00:01:00" receiveTimeout ="00:10:00" sendTimeout ="00:01:00"

                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

                     deadLetterQueue =自定义"持久=真" fullyOnce ="true"

                    deadLetterQueue="Custom" durable="true" exactlyOnce="true"

                     maxReceivedMessageSize ="65536" maxRetryCycles ="2". receiveErrorHandling =故障"

                    maxReceivedMessageSize="65536" maxRetryCycles="2" receiveErrorHandling="Fault"

                     receiveRetryCount ="5". retryCycleDelay ="00:30:00"; timeToLive =" 1.00:00:00"

                    receiveRetryCount="5" retryCycleDelay="00:30:00" timeToLive="1.00:00:00"

                     useSourceJournal ="false"; useMsmqTracing =假". queueTransferProtocol =本机"

                    useSourceJournal="false" useMsmqTracing="false" queueTransferProtocol="Native"

                     maxBufferPoolSize ="524288" useActiveDirectory ="false"

                    maxBufferPoolSize="524288" useActiveDirectory="false" 

                         customDeadLetterQueue =" net.msmq://localhost/private/MyCustomDLQ">

                         customDeadLetterQueue="net.msmq://localhost/private/MyCustomDLQ">

                   <b;< readerQuotas maxDepth =" 32" maxStringContentLength ="8192" maxArrayLength ="16384"

                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

                         maxBytesPerRead ="4096" maxNameTableCharCount ="16384"; />

                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />

                   <b;<安全模式=无">

                    <security mode="None">

                       <b;< transport msmqAuthenticationMode ="WindowsDomain"; msmqEncryptionAlgorithm ="RC4Stream"

                        <transport msmqAuthenticationMode="WindowsDomain" msmqEncryptionAlgorithm="RC4Stream"

                             msmqProtectionLevel ="Sign" msmqSecureHashAlgorithm =" Sha1" />

                            msmqProtectionLevel="Sign" msmqSecureHashAlgorithm="Sha1" />

                        < message clientCredentialType =" Windows" />

                        <message clientCredentialType="Windows" />

                    </security>

                    </security>

                </binding>

                </binding>

            </netMsmqBinding>

            </netMsmqBinding>

        </bindings>

        </bindings>

        < client>

        <client>

            <端点地址="net.msmq://localhost/private/MyServiceQueue"

            <endpoint address="net.msmq://localhost/private/MyServiceQueue"

                 binding ="netMsmqBinding"; bindingConfiguration ="NetMsmqBinding_IMyService"

                binding="netMsmqBinding" bindingConfiguration="NetMsmqBinding_IMyService"

                 contract ="MyService.IMyService";名称="NetMsmqBinding_IMyService">

                contract="MyService.IMyService" name="NetMsmqBinding_IMyService">

                < identity>

                <identity>

                    < dns value ="本地主机" />

                    <dns value="localhost" />

                </identity>

                </identity>

            </endpoint>

            </endpoint>

        </client>

        </client>

    </system.serviceModel>

    </system.serviceModel>

</configuration>

</configuration>

 

//客户端代码

            使用(TransactionScope scope = new TransactionScope())

            using (TransactionScope scope = new TransactionScope())

             {

            {

                 MyService.MyServiceClient代理=新的MyService.MyServiceClient();

                MyService.MyServiceClient proxy = new MyService.MyServiceClient();

 

                尝试

                try

                 {

                {

                     proxy.Open();

                    proxy.Open();

                     proxy.GetData(1);

                    proxy.GetData(1);

                }

                }

              最终

                finally

                 {

                {

                     proxy.Close();

                    proxy.Close();

                }

                }

 

                 scope.Complete();

                scope.Complete();

            }

            }

//DLQ服务app.config:

//DLQ Service app.config :

<?xml version ="1.0" encoding ="utf-8" ?>

<?xml version="1.0" encoding="utf-8" ?>

<配置>

<configuration>

 < system.web>

  <system.web>

    < compilation debug =" true" />

    <compilation debug="true" />

 </system.web>

  </system.web>

 < system.serviceModel>

  <system.serviceModel>

    <服务>

    <services>

      <服务名=" ClientDQL.MyDLQService">

      <service name="ClientDQL.MyDLQService">

        <端点地址=" net.msmq://localhost/private/MyCustomDLQ"

        <endpoint address="net.msmq://localhost/private/MyCustomDLQ"

                   binding ="netMsmqBinding"

                  binding="netMsmqBinding"

                   contract ="ClientDQL.IMyDLQService"

                  contract="ClientDQL.IMyDLQService"

                   bindingConfiguration ="NoMSMQSecurity">

                  bindingConfiguration="NoMSMQSecurity">

          < identity>

          <identity>

            < dns value ="本地主机" />

            <dns value="localhost" />

          </identity>

          </identity>

        </endpoint>

        </endpoint>

      </service>

      </service>

    </services>

    </services>

    < bindings>

    <bindings>

      < netMsmqBinding>

      <netMsmqBinding>

        <绑定名称=" NoMSMQSecurity">

        <binding name = "NoMSMQSecurity">

          <安全模式=无">

          <security mode = "None">

          </security>

          </security>

        </binding>

        </binding>

      </netMsmqBinding>

      </netMsmqBinding>

    </bindings>

    </bindings>

 </system.serviceModel>

  </system.serviceModel>

</configuration>

</configuration>

//DLQ服务代码

名称空间ClientDQL
namespace ClientDQL

推荐答案

你好,

messege不会立即放入死信队列.每个MSMQ消息都包含一些有关其生存时间的信息.首先,将消息放置在外出队列中,然后客户端计算机尝试将消息发送到目标队列. 到达目标队列,等待处理.所有这些操作可能需要一些时间,因此要检查生存时间间隔.如果间隔到期,则邮件将被放入死信队列.NetMsmq绑定使用1天作为默认值 时间间隔,但可以在timeToLive属性中进行更改.必须在客户端上配置此属性.

messege is not placed to dead letter queue immediately. Each MSMQ message contains some information about its time to live. First the message is placed ot out going queue and client machine tryes to send message to destination queue. When the message reaches the destination queue it waits for processing. All these action can take some time so the time to live interval is checked. If the interval expires the message is placed to dead letter queue. NetMsmq binding uses 1 day as default value for the interval but it can be changed in timeToLive attribute. This attribute has to be configured on the client.

最诚挚的问候,
拉迪斯拉夫

Best regards,
Ladislav


这篇关于在WCF MSMQ 4.0中读取自定义DLQ的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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