首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Orion-QL订阅配置

Orion-QL订阅配置
EN

Stack Overflow用户
提问于 2021-07-26 10:30:16
回答 1查看 152关注 0票数 1

我有带很多物联网传感器的设备。我想对这些设备进行批量读取,并将这些数据批量写入CrateDB。每1秒从传感器获取100个数据。

例如,如何使用量子跃迁代理将5秒的批处理数据(500个数据)一起写入CrateDB?我是否应该在Orion订阅(节流等)中进行此配置?

EN

回答 1

Stack Overflow用户

发布于 2021-07-27 07:29:47

使用NGSI-v2,可以使用/v2/op/update端点实现批处理更新,例如:

代码语言:javascript
复制
curl -L -X POST 'http://localhost:1026/v2/op/update' \
-H 'Content-Type: application/json' \
--data-raw '{
  "actionType":"update",
  "entities":[
    {
      "id":"urn:ngsi-ld:Product:001", "type":"Product",
      "price":{"type":"Integer", "value": 1199}
    },
    {
      "id":"urn:ngsi-ld:Product:002", "type":"Product",
      "price":{"type":"Integer", "value": 1199},
      "size": {"type":"Text", "value": "L"}
    }
  ]
}'

使用NGSI-LD,您可以使用/ngsi-ld/v1/entityOperations/upsert

代码语言:javascript
复制
curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/entityOperations/upsert' \
-H 'Content-Type: application/json' \
-H 'Link: <http://path-to-context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/ld+json' \
--data-raw '[
    {
      "id": "urn:ngsi-ld:TemperatureSensor:002",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 21,
            "unitCode": "CEL"
      }
    },
    {
      "id": "urn:ngsi-ld:TemperatureSensor:003",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 27,
            "unitCode": "CEL"
      }
    }
]'

您没有说明您的多传感器是否能够发送NGSI呼叫--如果它不能发送NGSI,但能够以其他格式发送批处理读数,那么您只需要一个微服务来为您进行转换--这里可以在GitHub上找到一个例子--有关代码的评论可以在FIWARE基金会的视频教程中找到。

一旦您安全地以NGSI格式发送设备数据,您就可以解决问题的后半部分。QuantumLeap为NGSI-v2NGSI-LD都提供了教程,它们的关键是创建一个通知任何更改的订阅。

NGSI-v2

代码语言:javascript
复制
curl -iX POST \
  'http://localhost:1026/v2/subscriptions/' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "description": "Notify QuantumLeap of count changes of any Motion Sensor",
  "subject": {
    "entities": [
      {
        "idPattern": "Motion.*"
      }
    ],
    "condition": {
      "attrs": [
        "count"
      ]
    }
  },
  "notification": {
    "http": {
      "url": "http://quantumleap:8668/v2/notify"
    },
    "attrs": [
      "count"
    ],
    "metadata": ["dateCreated", "dateModified"]
  }
}'

NGSI-LD

代码语言:javascript
复制
curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/subscriptions/' \
-H 'Content-Type: application/ld+json' \
-H 'NGSILD-Tenant: openiot' \
--data-raw '{
  "description": "Notify me of all feedstock changes",
  "type": "Subscription",
  "entities": [{"type": "FillingLevelSensor"}],
  "watchedAttributes": ["filling"],
  "notification": {
    "attributes": ["filling", "location"],
    "format": "normalized",
    "endpoint": {
      "uri": "http://quantumleap:8668/v2/notify",
      "accept": "application/json"
    }
  },
   "@context": "http://path-to-context/ngsi-context.jsonld"
}'

除非您只想对传入的数据进行采样,否则不需要使用throttling参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68528318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档