首页 > 解决方案 > 如何使用 Orion Context Broker 将 TimeInstant、CreationDate 和 ModifiedDate 添加到 CrateDB?

问题描述

我正在建立一个固件框架,不幸的是我不得不添加历史传感器值。但对于其他用例,我还需要创建日期和修改日期。

因此,我添加了带有变量“TimeInstant”的属性“元数据”。然后我创建一个实体,为该实体创建一个 Orion-Subscription 并使用我的旧 Sensor-Valses 更新该实体。

我发送到 Orion-Context Broker 以更新属性的 Json 文件如下所示:

{
"metadata": {
    "TimeInstant": {
        "type": "DateTime",
        "value": "2015-02-02T11:35:25.0000Z"
    }
},
"type": "Number",
"value": 0.0132361 }

我的 Mongo-DB 中的输出如下:

"_id": {
    "id": "urn:ngsi-ld:SensorB-K1200____",
    "type": "Sensor",
    "servicePath": "/test/servicepath"
},
"attrNames": [
    "Sensor_value"
],
"attrs": {
    "Sensor_value": {
        "value": 0.01632361,
        "type": "Number",
        "md": {
            "TimeInstant": {
                "type": "DateTime",
                "value": 1422876989
            }
        },
        "mdNames": [
            "TimeInstant"
        ],
        "creDate": 1568712813,
        "modDate": 1568735930
    }
},
"creDate": 1568712813,
"modDate": 1568735930,
"lastCorrelator": "0a129232-d964-11e9-8e5a-0242ac130009" }

但是我的 Crate-DB 只有以下列: entity_id entity_type fiware_servicepath sensor_value time_index

我的订阅文件如下所示:

{
"expires": "2019-12-24T18:00:00",
"notification": {
    "http": {
        "url": "http://quantumleap:8668/v2/notify"
    },
    "metadata": [
        "dateCreated",
        "dateModified",
        "TimeInstant"
    ]
},
"subject": {
    "entities": [
        {
            "id": "urn:ngsi-ld:SensorB-K1200____",
            "type": "Sensor"
        }
    ]
},
"throttling": 0 }

我尝试更改订阅文件中的“元数据”属性,也尝试重新启动 Crate-DB、ContextBroker 例如。

我希望 CrateDb 显示所有三个值:“dateCreated”、“dateModified”和“TimeInstant”。

标签: fiwarefiware-orioncratedb

解决方案


您是否查看了 Orion 实际发送给 QuantumLeap 的消息通知是什么?

至于有效载荷,我会尝试如下:

{
  "TimeInstant": {
    "type": "DateTime",
    "value": "2015-02-02T11:35:25.0000Z"
  },
  "type": "Number",
  "value": 0.0132361
}

在内部,我们通常将此类场景用作属性名称dateObserved,但不会有任何区别TimeInstant

我实际上不确定您是否可以将元数据附加到 NGSI 消息的根,我相信它们应该只附加到属性。总之,QuantumLeaps 不支持 NGSI 元数据(即附加到 NGSI 属性的元数据)。它仍然支持基于它们的时间索引。

Quantum Leap 处理 TimeInstant 元数据和其他时间元数据的方式是通过time_index. 请参阅此处的文档:https ://quantumleap.readthedocs.io/en/latest/user/#time-index


推荐阅读