无法添加Azure Service Bus主题订阅过滤规则

时间:2017-09-27 09:42:51

标签: c# .net azure azureservicebus azure-servicebus-topics

我试图在服务总线主题订阅中创建过滤规则。

 foreach(var reciver in recivers)
        {
            try
            {
                var client = SubscriptionClient.CreateFromConnectionString(ServiceBusConnectionString, reciver.TopicName, reciver.SubscriptionName);

                string ruleName = "customRule2";
                client.RemoveRule(ruleName);

                var filter = reciver.Reciver.GetFilter();
                var ruleDescription = new RuleDescription(ruleName, filter);

                client.AddRule(ruleDescription);
                client.RemoveRule("$Default");

                client.OnMessage((msg) => {
                    reciver.Reciver.Recive(msg);
                });                    
            }
            catch(Exception ex)
            {

            }
        }

异常来自

client.AddRule(ruleDescription);

我尝试删除以下行

client.RemoveRule(ruleName);

它正常工作。但是第二次运行应用程序时,它会出现异常情况"消息传递实体已经存在"

但是我需要删除现有规则并在启动订阅时添加相同的规则。

以下是完整的异常消息

  

Microsoft.ServiceBus.Messaging.MessagingException:服务无法处理请求;请重试该操作。有关异常类型和正确异常处理的更多信息,请参阅http://go.microsoft.com/fwlink/?LinkId=761101 TrackingId:a08300d4-9f59-4455-8519-5410198ba444_G16,SystemTracker:vp-servicebus-poc:主题:test-topic2,时间戳:9/27 / 2017 9:17:35 AM ---> System.ServiceModel.FaultException 1[System.ServiceModel.ExceptionDetail]: The service was unable to process the request; please retry the operation. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101 TrackingId:a08300d4-9f59-4455-8519-5410198ba444_G16, SystemTracker:vp-servicebus-poc:Topic:test-topic2, Timestamp:9/27/2017 9:17:35 AM at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage) at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.EndRequest(IAsyncResult result) at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory 1.RequestSessionChannel.RequestAsyncResult。<> c.b__9_3(RequestAsyncResult thisPtr,IAsyncResult r)      在Microsoft.ServiceBus.Messaging.IteratorAsyncResult 1.StepCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.ServiceBus.Common.AsyncResult 1.End(IAsyncResult asyncResult)      在Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory 1.RequestSessionChannel.EndRequest(IAsyncResult result) at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory 1.RedirectContainerSessionChannel.RequestAsyncResult。<> c__DisplayClass8_1.b__4(RequestAsyncResult thisPtr,IAsyncResult r)      在Microsoft.ServiceBus.Messaging.IteratorAsyncResult 1.StepCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.ServiceBus.Common.AsyncResult 1.End(IAsyncResult asyncResult)      在Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory 1.RedirectContainerSessionChannel.EndRequest(IAsyncResult result) at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory 1.RequestSessionChannel.RequestAsyncResult。<> c.b__9_3(RequestAsyncResult thisPtr,IAsyncResult r)      在Microsoft.ServiceBus.Messaging.IteratorAsyncResult 1.StepCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.ServiceBus.Common.AsyncResult 1.End(IAsyncResult asyncResult)      在Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory 1.RequestSessionChannel.EndRequest(IAsyncResult result) at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult 1.<> c.b__18_3(TIteratorAsyncResult thisPtr,IAsyncResult a)      在Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult结果)   ---从抛出异常的先前位置开始的堆栈跟踪结束---      在Microsoft.ServiceBus.Common.AsyncResult.End [TAsyncResult](IAsyncResult结果)      在Microsoft.ServiceBus.Messaging.Sbmp.SbmpSubscriptionClient.OnEndAddRule(IAsyncResult结果)      ---内部异常堆栈跟踪结束---      在Microsoft.ServiceBus.Messaging.Sbmp.SbmpSubscriptionClient.OnEndAddRule(IAsyncResult结果)      在Microsoft.ServiceBus.Messaging.SubscriptionClient.AddRule(RuleDescription description)      在G:\ Documents \ Visual Studio 2015 \ Projects \ ServiceBusReciver \ ServiceBusReciver \ ServiceBusReciverBuilder.cs中的ServiceBusReciver.ServiceBusReciverBuilder.InitRecivers():第42行

1 个答案:

答案 0 :(得分:0)

WindowsAzure.ServiceBus.dll版本存在问题。 我将WindowsAzure.ServiceBus.dll的版本从4.1.3降级到4.1.2,这是完美的。

编辑:这个问题又来了