【问题标题】:Orion-QL subscription configurationOrion-QL 订阅配置
【发布时间】:2021-10-02 07:13:50
【问题描述】:

我的设备带有许多 IoT 传感器。我想从这些设备批量读取并将这些数据批量写入 CrateDB。每 1 秒从传感器获取 100 条数据。

如何使用 Quantum Leap 代理一次获取 5 秒的批处理数据(500 个数据)并将其写入 CrateDB?我应该在 Orion 中进行此配置-QL 订阅(节流等)?

【问题讨论】:

    标签: fiware throttling fiware-orion


    【解决方案1】:

    使用 NGSI-v2 批量更新是使用 /v2/op/update 端点实现的,例如:

    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:

    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 基金会的Video Tutorials 中找到代码的评论。

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

    NGSI-v2

    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

    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 参数不是必需的,除非您只想对传入数据进行采样。

    【讨论】:

    • 所以我想批量处理单个实体中的很多属性,实体更新不多,这可能吗? @JasonFox
    • 一个实体中的许多属性只是一个简单的 PATCH /entities/&lt;urn:entity-id&gt;。您可以直接使用 NGSI 或为此使用 IoT 代理(实际上在后台使用批处理端点,但批处理 upsert 只是一个实体)
    • 一个实体中的单个属性是 PATCH /entities/&lt;urn:entity-id&gt;/attrs
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多