【问题标题】:Azure topic subscription filter / Subscription RuleAzure 主题订阅筛选器/订阅规则
【发布时间】:2019-06-28 10:01:18
【问题描述】:

我创建了一个示例客户端,它侦听附加到服务总线主题的订阅。现在,每当在该主题中发布消息时,它都会被收听订阅者的客户端捕获。 (如下文所述)

https://github.com/Azure/azure-service-bus/tree/master/samples/DotNet/GettingStarted/Microsoft.Azure.ServiceBus/TopicSubscriptionWithRuleOperationsSample

现在我想添加一个过滤器/规则,以便只有通过过滤器中定义的特定条件的消息才应该被订阅。

例如,下面是消息内容json,它以字符串形式给出,

"{"firstName": "Tony", "LastName": "Stark", "nickName": "Iron Man", "occupation":"actor"}"

如何创建仅接收 "occupation": "actor" 的消息的订阅规则。根据 azure 文档,我们需要 SqlFilter 但是到目前为止还没有运气,

https://docs.microsoft.com/en-us/azure/service-bus-messaging/topic-filters

https://www.terraform.io/docs/providers/azurerm/r/servicebus_subscription_rule.html#example-usage-sql-filter-

我们正在使用 terraform 在 azure 云中创建资源。上面链接中建议的模块,但是如何定义sql_filter要考虑"occupation":"actor"

filter_type = "SqlFilter" sql_filter = "???"

我试过如下,但得到无效字符“:”

sql_filter = "'occupation':'actor'"

【问题讨论】:

    标签: azure terraform azure-servicebus-topics terraform-provider-azure azure-servicebus-subscriptions


    【解决方案1】:

    您不能在消息正文中的属性上定义SQL Filter,因为您的消息正文可以是任何内容。 SQL Filters 处理 custom properties 的消息。

    例如,如果您想在occupation 上创建一个过滤器,您需要在您的消息中定义一个自定义属性并将其值设置为actor。那么您的 SQL 过滤器表达式将如下所示:

    sql_filter = "occupation = 'actor'"
    

    您可能会发现这篇博文很有用:https://www.markheath.net/post/azure-service-bus-filtered-subscriptions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多