How to create extended subscription expression in Orion Context Broker NGSIv2?
According to the official documentation of Orion Context Broker NGSIv2 :
You can enable filtering of expressions in conditions. For example, to receive a notification not only if the pressure changes, but if it changes within the range of 700-800. This is an advanced topic, see the Subscriptions section of the NGSIv2 specification .
There are no NGSIv2 signatures notifyConditions
like NGSIv1, it has been replaced with a subject.condition object:
condition
: condition for triggering notifications. This field is optional and can contain two properties, both optional:
attrs
: array of attribute names
expression
: Expression consisting ofq
,mq
,georel
,geometry
andcoords
(see "Operation Entity List" above this field.)
When we use it subject.condition.attrs
, it contains an array of attribute names, these names define "trigger attributes", that is, attributes that, when created / modified due to the creation or update of an object, trigger a notification.
But subject.condition.expression
there is no example for in the official docs.
Retrieving puzzle pieces can be output:
- It is possible to combine
subject.condition.expression
andsubject.condition.attrs
. If I set and assign another expression, eg. attr foo with the expression 'boo> 10', what will it do? Will it behave likeOR
orAND
? - Multiple expressions can be set. Will it behave like
OR
orAND
?
It would be nice to have some examples of these more complex signatures that combine different ways to differentiate objects in a subscription.
NOTE: This question is related to Orion Version 1.7.0 +
source to share
I think the following example: presentation of NGSIv2 to developers already familiar with NGSIv1 (slide 34 in the current version) might help clarify.
Example : subscribe to speed changes on any object of any type ending in Vehicle (e.g. RoadVehicle, AirVehicle, etc.) when the speed is greater than 90, its average metadata is between 80 and 90 and the distance from the vehicle to the center of Madrid is less than 100 km.
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 shown in this example, you can use different conditions ( q
, mq
, geokriya, etc.), and they are interpreted in the sense of Morevoer, q
and mq
allow us to interpret complex expressions in terms of AND, for example:
"q": "speed>90;engine!=fail",
Note that q
and mq
when they appear in subscriptions expression
follow the same rules as for synchronous requests (i.e. GET /v2/entities?q=...
). These rules are described in the "Simple Query Language" section of the NGSIv2 specification .
source to share