如何在 Orion Context Broker NGSIv2 中创建高级订阅表达式?
How to create advanced subscriptions expression at Orion Context Broker NGSIv2?
根据official documentation of 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. This is an advanced topic, see the "Subscriptions"
section in the NGSIv2 specification.
在 NGSIv2 订阅中没有 notifyConditions
例如 NGSIv1 ,它被替换为 subject.condition object:
condition
: Condition to trigger notifications. This field is optional
and it may contain two properties, both optional:
attrs
: array of attribute names
expression
: an expression composed of q
, mq
, georel
,
geometry
and coords
(see "List entities" operation above about this
field)
当我们使用 subject.condition.attrs
时,它包含一个属性名称数组,这些名称定义 "triggering attributes",即在 creation/change 由于实体创建或更新触发通知的属性.
但是,对于subject.condition.expression
,官方文档中没有示例。
得到拼图可以推导出:
- 可以结合使用
subject.condition.expression
和 subject.condition.attrs
。如果我设置和归因于不同的表达方式,例如。 attr foo with expression 'boo>10' 它会做什么?这会表现得像 OR
或 AND
吗?
- 可以设置多个表达式。这会表现得像
OR
或 AND
吗?
最好能有这些更复杂的订阅的一些示例,这些示例结合了在订阅中分隔实体的不同方式。
注意:此问题与 Orion Version 1.7.0+
相关
我认为来自 NGSIv2 Overview for Developers That Already Know 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
要求:
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"
}
}
},
...
}
如本例所示,您可以使用不同的条件(q
、mq
、geoquery 等),它们在 AND 意义上进行解释。此外,q
和 mq
也允许在 AND 意义上解释复杂的表达式,例如:
"q": "speed>90;engine!=fail",
请注意,当 q
和 mq
出现在订阅 expression
中时,它们遵循与出现在同步查询(即 GET /v2/entities?q=...
中)相同的规则。 NGSIv2 specification.
中的 "Simple Query Language" 部分描述了这些规则
根据official documentation of 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. This is an advanced topic, see the "Subscriptions" section in the NGSIv2 specification.
在 NGSIv2 订阅中没有 notifyConditions
例如 NGSIv1 ,它被替换为 subject.condition object:
condition
: Condition to trigger notifications. This field is optional and it may contain two properties, both optional:
attrs
: array of attribute names
expression
: an expression composed ofq
,mq
,georel
,geometry
andcoords
(see "List entities" operation above about this field)
当我们使用 subject.condition.attrs
时,它包含一个属性名称数组,这些名称定义 "triggering attributes",即在 creation/change 由于实体创建或更新触发通知的属性.
但是,对于subject.condition.expression
,官方文档中没有示例。
得到拼图可以推导出:
- 可以结合使用
subject.condition.expression
和subject.condition.attrs
。如果我设置和归因于不同的表达方式,例如。 attr foo with expression 'boo>10' 它会做什么?这会表现得像OR
或AND
吗? - 可以设置多个表达式。这会表现得像
OR
或AND
吗?
最好能有这些更复杂的订阅的一些示例,这些示例结合了在订阅中分隔实体的不同方式。
注意:此问题与 Orion Version 1.7.0+
相关我认为来自 NGSIv2 Overview for Developers That Already Know 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
要求:
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"
}
}
},
...
}
如本例所示,您可以使用不同的条件(q
、mq
、geoquery 等),它们在 AND 意义上进行解释。此外,q
和 mq
也允许在 AND 意义上解释复杂的表达式,例如:
"q": "speed>90;engine!=fail",
请注意,当 q
和 mq
出现在订阅 expression
中时,它们遵循与出现在同步查询(即 GET /v2/entities?q=...
中)相同的规则。 NGSIv2 specification.