我有带很多物联网传感器的设备。我想对这些设备进行批量读取,并将这些数据批量写入CrateDB。每1秒从传感器获取100个数据。
例如,如何使用量子跃迁代理将5秒的批处理数据(500个数据)与一起写入CrateDB?我是否应该在Orion订阅(节流等)中进行此配置?
发布于 2021-07-27 07:29:47
使用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基金会的视频教程中找到。
一旦您安全地以NGSI格式发送设备数据,您就可以解决问题的后半部分。QuantumLeap为NGSI-v2和NGSI-LD都提供了教程,它们的关键是创建一个通知任何更改的订阅。
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参数。
https://stackoverflow.com/questions/68528318
复制相似问题