根据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 订阅中,没有像 NGSIv1 那样的 notifyConditions
,它被 subject.condition 对象取代:
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
时,它包含一个属性名称数组,这些名称定义“触发属性”,即由于实体创建或更新而触发创建/更改的属性通知。
但是,对于subject.condition.expression
,官方文档中没有示例。
获取拼图碎片可以推断:
- 可以将
subject.condition.expression
和subject.condition.attrs
结合起来。如果我设置并赋予不同的表达式,例如。 attr foo 带有表达式 'boo>10' 它将做什么?这会像OR
或AND
一样吗? - 可以设置多个表达式。这会像
OR
或AND
一样吗?
如果有一些这些更复杂的订阅的示例,结合了分隔订阅中实体的不同方式,那就太好了。
注意:此问题与 Orion 版本 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 含义进行解释。 Morevoer、q
和 mq
还允许以 AND 方式解释复杂表达式,例如:
"q": "speed>90;engine!=fail",
请注意,q
和 mq
当它们出现在订阅 表达式
中时,遵循与它们出现在同步查询中时相同的规则(即GET/v2/entities?q=...
)。 NGSIv2 specification 中的“简单查询语言”部分描述了这些规则。 .
关于fiware - 如何在 Orion Context Broker NGSIv2 上创建高级订阅表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45490529/