服务总线队列主机服务的异常处理

时间:2013-02-13 21:20:47

标签: azure azureservicebus

我有一个连接到服务总线队列的WCF服务,准备好接收消息。这很好用,但如果我有处理消息的问题,我希望能够将消息标记为DeadLetter。目前,如果我的代码抛出异常,消息仍会从队列中删除,但我希望能够在配置中指定不从队列中删除但将其标记为DeadLetter。我做了一些搜索,我无法弄清楚如何做到这一点。我目前正在将该服务作为Windows服务运行

  

Uri baseAddress = ServiceBusEnvironment.CreateServiceUri(“sb”,   “namespace”,“servicequeue”);                   _serviceHost = new ServiceHost(typeof(PaperlessImportServiceOneWay),baseAddress);   _serviceHost.Open();

配置:

<services>
      <service name="Enrollment.ServiceOneWay">
        <endpoint name="ServiceOneWay"
                  address="sb://namespace.servicebus.windows.net/servicequeue"
                  binding="netMessagingBinding"
                  bindingConfiguration="messagingBinding"
                  contract="IServiceOneWaySoap"
                  behaviorConfiguration="sbTokenProvider" />
      </service>
</services>
      <netMessagingBinding>
        <binding name="messagingBinding" closeTimeout="00:03:00" openTimeout="00:03:00"
               receiveTimeout="00:03:00" sendTimeout="00:03:00" sessionIdleTimeout="00:01:00"
               prefetchCount="-1">
          <transportSettings batchFlushInterval="00:00:01" />
        </binding>
      </netMessagingBinding>

<behavior name="sbTokenProvider">
          <transportClientEndpointBehavior>
            <tokenProvider>
              <sharedSecret issuerName="owner" issuerSecret="XXXXXXXXXXXXXXXXXXXXXXXX" />
            </tokenProvider>
          </transportClientEndpointBehavior>
        </behavior>

1 个答案:

答案 0 :(得分:1)

在您的操作界面中添加此项 [ReceiveContextEnabled(Manual Control = true)] 然后您可以设法提交或放弃该消息 在此链接中找到它: http://msdn.microsoft.com/en-us/library/windowsazure/hh532034.aspx