SQLFilter 基于 Azure 服务总线订阅中的系统属性
SQLFilter based on System Properties in Azure Service Bus Subscription
我正在设置 topic/subscription 服务,需要有关 SQL 过滤器语法的帮助,以便我可以访问 BrokeredMessage 属性,特别是 To 属性。 SQL 过滤器访问邮件系统属性的正确语法是什么?
我有一个使用本教程的工作示例,我可以根据需要向我的 topic/subscription 发送和接收:https://azure.microsoft.com/en-us/documentation/articles/service-bus-queues-topics-subscriptions/
但是,现在我想根据 BrokeredMessage 的收件人 属性 为每个订阅设置 SQL 过滤器。我遵循的教程提到有可能 "When a subscription is created, you can supply a filter expression that operates on the properties of the message, both the system properties (for example, Label) and custom application properties (for example, StoreName.)"
如果我设置自定义 属性,例如StoreName,像这样:
message.Properties.Add("StoreName", "TestMe");
并使用 SQL 过滤器设置订阅,如下所示:
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("StoreName = 'TestMe'"));
订阅过滤符合预期。但是,如果我尝试按照文章中的描述使用 BrokeredMessage 对象 To 属性(或与此相关的标签),我将无法使其正常工作。我尝试了以下 SQL 过滤器,但没有成功。访问消息的系统属性的正确语法是什么?
BrokeredMessage message = new BrokeredMessage();
message.To = "TestMe";
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("To = 'TestMe'"));
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("Message.To= 'TestMe'"));
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("MessageTo= 'TestMe'"));
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("messageto= 'TestMe'"));
来自这篇文章Topic Subscription Filters:
SQL Filters - A SqlFilter
holds a SQL-like condition expression that is evaluated in the broker against the arriving messages' user-defined properties and system properties. All system properties (which are all properties explicitly listed on the BrokeredMessage class) must be prefixed with sys.
in the condition expression. The SQL subset implements testing for existence of properties (EXISTS
), testing for null-values (IS NULL
), logical NOT
/AND
/OR
, relational operators, numeric arithmetic, and simple text pattern matching with LIKE
.
因此,在您的情况下,您需要在 sys.To
属性:
上创建一个 SqlFilter
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription",
new SqlFilter("sys.To = 'TestMe'"));
我正在设置 topic/subscription 服务,需要有关 SQL 过滤器语法的帮助,以便我可以访问 BrokeredMessage 属性,特别是 To 属性。 SQL 过滤器访问邮件系统属性的正确语法是什么?
我有一个使用本教程的工作示例,我可以根据需要向我的 topic/subscription 发送和接收:https://azure.microsoft.com/en-us/documentation/articles/service-bus-queues-topics-subscriptions/
但是,现在我想根据 BrokeredMessage 的收件人 属性 为每个订阅设置 SQL 过滤器。我遵循的教程提到有可能 "When a subscription is created, you can supply a filter expression that operates on the properties of the message, both the system properties (for example, Label) and custom application properties (for example, StoreName.)"
如果我设置自定义 属性,例如StoreName,像这样:
message.Properties.Add("StoreName", "TestMe");
并使用 SQL 过滤器设置订阅,如下所示:
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("StoreName = 'TestMe'"));
订阅过滤符合预期。但是,如果我尝试按照文章中的描述使用 BrokeredMessage 对象 To 属性(或与此相关的标签),我将无法使其正常工作。我尝试了以下 SQL 过滤器,但没有成功。访问消息的系统属性的正确语法是什么?
BrokeredMessage message = new BrokeredMessage();
message.To = "TestMe";
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("To = 'TestMe'"));
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("Message.To= 'TestMe'"));
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("MessageTo= 'TestMe'"));
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription", new SqlFilter("messageto= 'TestMe'"));
来自这篇文章Topic Subscription Filters:
SQL Filters - A
SqlFilter
holds a SQL-like condition expression that is evaluated in the broker against the arriving messages' user-defined properties and system properties. All system properties (which are all properties explicitly listed on the BrokeredMessage class) must be prefixed withsys.
in the condition expression. The SQL subset implements testing for existence of properties (EXISTS
), testing for null-values (IS NULL
), logicalNOT
/AND
/OR
, relational operators, numeric arithmetic, and simple text pattern matching withLIKE
.
因此,在您的情况下,您需要在 sys.To
属性:
SqlFilter
namespaceManager.CreateSubscription("MyNSTestTopic", "TestSubscription",
new SqlFilter("sys.To = 'TestMe'"));