简体   繁体   中英

Orion Subscription to update entity attributes from CrateDB, on value changes

Is there a convenient way to subscribe to update an attribute, each time another attribute changes?

I have this entity on Orion:

{
  "id": "Asset:001",
  "type": "SomeType",
  "Input": {
    "type": "Text",
    "value": "State",
    "metadata": {}
  },
  "Output": {
    "type": "Float",
    "value": null,
    "metadata": {}
  }
}

I subscribe to notify value changes to Quantumleap:

curl -s -o /dev/null -X POST \
    'http://orion:1026/v2/subscriptions/' \
    -H 'Content-Type: application/json' \
    -d '{
  "description": "Orion notify Quantumleap on State changhes",
  "subject": {
    "entities": [
      {
        "idPattern": ".*",
        "type": "Sometype"
      }
    ],
    "condition": {
      "attrs": [
        "state"
      ]
    }
  },
  "notification": {
    "http": {
      "url": "http://quantumleap:8668/v2/notify"
    },
    "attrs": [
      "State"
    ],
    "metadata": []
  }
}'

And I got my data on CrateDB where I made some calculation. Then I would like to get the results of this computing, and put back as an attribute to the entity Asset:001 .

Now I get this done by a script, but it would be nice to achieve the same result with a subscription, is this possible?

Thanks!!

The attributes in attrs within notification are the ones to be included in the notification. The attributes in attrs within condition are the ones which change trigger the notification.

You can use a different set of attributes in each array, so the use case you describe in covered.

For instance, changes in attribute A will notify the value of attribute B using something like this:

{
  ...
  "subject": {
    ...
    "condition": {
      "attrs": [
        "A"
      ]
    }
  },
  "notification": {
    ...
    "attrs": [
      "B"
    ]
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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