Search code examples
fiwarefiware-orion

FIWARE Orion, NGSIv2 subscription in attributes with structured values


I'm working with Orion Contex Broker and I need to receive notifications when a parameter in a structured attribute changes its value. An example:

  1. Subscription:
curl -iX POST \
--url 'http://localhost:1026/v2/subscriptions' \
--header 'content-type: application/json' \
--data '{
   "description":"Notify me of Store changes in street Address",
   "subject":{
      "entities":[
     {
        "idPattern":".*",
        "type":"Store"
     }
      ],
      "condition":{
     "attrs":[
        "address.streetAddress"
     ]
      }
   },
   "notification":{
      "http":{
     "url":"http://localhost:3000/subscription/store-change"
      }
   }
}'
  1. Create entity:
curl -iX POST \
--url 'http://localhost:1026/v2/op/update' \
-H 'Content-Type: application/json' \
-d '{
   "actionType":"append",
   "entities":[
      {
         "type":"Store",
         "id":"urn:ngsi-ld:Store:001",
         "address":{
            "type":"PostalAddress",
            "value":{
               "streetAddress":"Old",
               "addressRegion":"Berlin"
            }
         },
         "name":{
            "type":"Text",
            "value":"Bösebrücke Einkauf"
         }
      }
   ]
}'
  1. Update the entity:
curl -iX PATCH \
--url 'http://localhost:1026/v2/entities/urn:ngsi-ld:Store:001/attrs' \
-H 'Content-Type: application/json' \
-d '{
   "address":{
      "type":"PostalAddress",
      "value":{
         "streetAddress":"Bornholmer"
      }
   }
}'

The expected result would be to receive a notification when the entity was created and update. Another possibility could be the "condition expressions". However one of kind: "q": "address.streetAddress!=${previousValue}" is not implemented yet.


Solution

  • Attributes within NGSI are usually numbers or strings - this typically leads to a very flat data model. In this case when the attribute value changes the subscription would be fired.

    JSON objects (such as address above) are also supported, but the change occurs whenever the Object's value change and is not specifically bound to a sub attribute Hence

    "attrs":[
       "address.streetAddress"
    ]
    

    Would need to be:

    "attrs":[
       "address"
    ]
    

    However, the q parameter could be used to filter against a specific sub-attribute e.g. q=address.streetAddress!="Old" - and the listening interface could amend the subscription after it has fired.