如何在 Orion Context Broker 通知自定义负载 (NGSIV2) 中使用属性元数据令牌?

How to use attribute metadata token in Orion Context Broker notification custom payload (NGSIV2)?

NGSIv2 客户端可以使用简单的模板机制自定义 HTTP 通知消息。

考虑以下通知 notification.httpCustom 对象:

"httpCustom": {
  "url": "http://foo.com/entity/${id}",
  "headers": {
    "Content-Type": "text/plain"
  },
  "method": "PUT",
  "qs": {
    "type": "${type}"
  },
  "payload": "The temperature is ${temperature} degrees"
}

令牌 ${temperature} 将由当前上下文值解析。

认为该属性可以具有元数据值可以包含自定义数据,例如 temperature.scale,以存储“°C”或“°F”的值。我怎样才能在该消息中打印它?

虽然属性元数据在通知中有 2 个特殊元数据:

  • previousValue. The value of this metadata must be the previous value of the associated attribute. The type of this metadata must be the previous type of the associated attribute. If the type/value of previousValue is the same type/value than in the associated attribute, then the attribute has not actually changed its value.
  • actionType. It is included if the attribute to which it is attached was included in the request that triggered the notification. Its value depends on the request operation type: update for updates, append for the creation and delete for deletion. Its type is always Text.

最终结果应该是这样的消息:

The temperature is now -10 °C degrees before was 9.1 °C degrees

可以吗,谁用?

NGSIv2 stable version RC-2016.10 中指定的通知模板机制(参考当前 Orion Context Broker 版本的 NGSIv2 版本,即 1.7.0)未实现元数据值替换。它可能会在下一个版本中实现。