简体   繁体   English

Orion Subscription 在值更改时从 CrateDB 更新实体属性

[英]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:我订阅通知 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.我在CrateDB上得到了我的数据,在那里我做了一些计算。 Then I would like to get the results of this computing, and put back as an attribute to the entity Asset:001 .然后我想得到这个计算的结果,并作为一个属性放回实体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. attrs within notification中的属性是要包含在通知中的属性。 The attributes in attrs within condition are the ones which change trigger the notification. conditionattrs中的属性是更改触发通知的属性。

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:例如,属性A更改将使用如下方式通知属性B的值:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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