简体   繁体   English

如何在Orion Context Broker NGSIv2上创建高级订阅表达式?

[英]How to create advanced subscriptions expression at Orion Context Broker NGSIv2?

According to official documentation of Orion Context Broker NGSIv2 : 根据Orion Context Broker NGSIv2的官方文档

You can include filtering expressions in conditions. 您可以在条件中包含过滤表达式。 For example, to get notified not only if pressure changes, but if it changes within the range 700-800. 例如,不仅要通知压力是否有变化,而且是否在700-800范围内变化。 This is an advanced topic, see the "Subscriptions" section in the NGSIv2 specification . 这是一个高级主题,请参阅NGSIv2规范中的“订阅”部分。

At NGSIv2 subscriptions there is no notifyConditions such as NGSIv1 , it was replaced by subject.condition object: 在NGSIv2订阅中没有诸如notifyConditions类的notifyConditions,它被subject.condition对象替换:

condition : Condition to trigger notifications. condition :触发​​通知的条件。 This field is optional and it may contain two properties, both optional: 此字段是可选的,它可能包含两个属性,都是可选的:

  • attrs : array of attribute names attrs :属性名称数组

  • expression : an expression composed of q , mq , georel , geometry and coords (see "List entities" operation above about this field) expression :由qmqgeorelgeometrycoords组成的表达式(请参阅上面关于此字段的“List entities”操作)

When we use subject.condition.attrs , it contains an array of attributes names, these names define the "triggering attributes", ie attributes that upon creation/change due to entity creation or update trigger the notification. 当我们使用subject.condition.attrs ,它包含一个属性名称数组,这些名称定义了“触发属性”,即由于实体创建或更新而创建/更改时触发通知的属性。

But, for subject.condition.expression there is not example at official documentations. 但是,对于subject.condition.expression ,在官方文档中没有示例。

Getting pieces of puzzle is possible to deduce : 获取拼图可以推断:

  • Is possible do combine subject.condition.expression and subject.condition.attrs . 可以将subject.condition.expressionsubject.condition.attrs结合起来。 If I set and attribute different of expression,eg. 如果我设置和表达不同的表达式,例如。 attr foo with expression 'boo>10' what it will do ? attr foo表达'boo> 10'它会做什么? Will this behave like an OR or AND ? 这会像OR还是AND
  • Is possible to set multiple expressions. 可以设置多个表达式。 Will this behave like an OR or AND ? 这会像OR还是AND

It would be nice to have some examples of these more complex subscriptions combining the different ways of delimiting the entities in the subscription. 将这些更复杂的订阅的一些示例与订阅中的实体分隔的不同方式相结合将会很不错。

NOTE: This question is related to Orion Version 1.7.0+ 注意:此问题与Orion版本1.7.0+有关

I think the following example, from the NGSIv2 Overview for Developers That Already Know NGSIv1 presentation (slide 34 in the current version), could help to clarify. 我认为以下示例来自NGSIv2开发人员概述已经知道NGSIv1演示文稿(当前版本中的幻灯片34),可能有助于澄清。

Example : subscribe to speed changes in any entities of any type ending with Vehicle (such as RoadVehicle, AirVehicle, etc.) whenever speed is greater than 90 its average metadata is between 80 and 90 and the vehicle distance to Madrid city center is less than 100 km 例如 :订阅加快在任何类型的载体(如RoadVehicle,AirVehicle等)每当速度大于90的平均元数据80和90并马德里市中心的车辆距离小于之间结束的任何实体的变化100公里

Request: 请求:

POST /v2/subscriptions
...
{  
  "subject": {
    "entities": [
     {
        "idPattern": ".*",
        "typePattern": ".*Vehicle"
     },
    ],
    "condition": {
      "attrs": [ "speed"  ],
      "expression":  {
         "q": "speed>90",
         "mq": "speed.average==80..100",
         "georel": "near;maxDistance:100000",
         "geometry": "point",
         "coords": "40.418889,-3.691944"
      }
      }
    },
   ...
}

As this example illustrates, you can use different conditions ( q , mq , geoquery, etc.) and they are interpreted in the AND sense. 如本例所示,您可以使用不同的条件( qmq ,geoquery等),它们在AND意义上进行解释。 Morevoer, q and mq allow complex expressions interpreted also in the AND sense, such as: Morevoer, qmq允许在AND意义上解释的复杂表达式,例如:

"q": "speed>90;engine!=fail",

Note that q and mq when they appear in subscriptions expression follow the same rules than the ones when they appear in synchronous queries (ie GET /v2/entities?q=... ). 请注意, qmq出现在订阅expression遵循的规则与它们出现在同步查询中的规则相同(即GET /v2/entities?q=... )。 These rules are described in "Simple Query Language" section in the NGSIv2 specification . 这些规则在NGSIv2规范的 “简单查询语言”部分中描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM