httpCustom 负载中没有替换

No substitution in httpCustom payload

我想在 OCB 中创建一个 httpCustom 负载,但没有正确替换信息。我想我已经测试了所有我知道的方法但没有结果,有人可以帮助我。这是我的代码:

"notification": {
            "httpCustom": {
                "url": "http://xxxx.xxxx.xxxx:8080/api/v1/telemetry",
                "payload": "[{ %22temperature%22: %22${id}%22, %22humidity%22: %22${humidity}%22, %22battery%22: %22${battery}%22 }]"
            },
            "attrs": [
                "temperature","humidity","battery"
            ]
        },

我订阅时没有错误,但是当我在我的端点测试时没有替换宏 ${...},有效负载采用对象信息组合但没有值。

我已经测试了 write/send ${id} 作为负载中字段的当时值并且根本没有替换。用 URL 编码和 %22 测试它但没有成功,我认为可能是禁用替换?但我已经检查过了,它的值是假的。

这是一个 HTTP 响应:

{
  "method": "POST",
  "path": "/",
  "query": {},
  "headers": {
    "x-forwarded-for": "3.124.211.58",
    "x-forwarded-proto": "https",
    "x-forwarded-port": "443",
    "host": "83efe9565d48d8bc8cf298d7786b8042.m.pipedream.net",
    "x-amzn-trace-id": "Root=1-5f1bddce-7f2b4277458e77b98c0920d1",
    "content-length": "54",
    "user-agent": "orion/2.1.0 libcurl/7.29.0",
    "fiware-service": "example",
    "fiware-servicepath": "/example",
    "accept": "application/json",
    "content-type": "application/json",
    "fiware-correlator": "a7fcfe32-ce47-11ea-9723-0242ac14000a",
    "ngsiv2-attrsformat": "custom"
  },
  "bodyRaw": "[{ \"temperature\": \"\", \"humidity\": \"\", \"battery\": \"\" }]",
  "body": [
    {
      "temperature": "",
      "humidity": "",
      "battery": ""
    }
  ]
}

Orion 版本:2.1.0 并在 2.4.0 中测试

有什么帮助吗?提前致谢!!

我用 Orion 2.4.0 做了以下测试。 Orion 数据库在开始测试之前是空的。

首先,创建这个订阅:

curl -v localhost:1026/v2/subscriptions -s -S -H 'Content-Type: application/json' -d @- <<EOF
{
  "subject": {
    "entities": [
      {
        "id": "Device1",
        "type": "Device"
      }
    ]
  },
  "notification": {
    "httpCustom": {
      "url": "http://localhost:1027/api/v1/telemetry",
      "payload": "[{ %22temperature%22: %22${id}%22, %22humidity%22: %22${humidity}%22, %22battery%22: %22${battery}%22 }]"},
      "attrs": [
         "temperature","humidity","battery"
      ]
  }
}
EOF

接下来,在端口 1027 启动一个列表进程:

nc -l -p 1027

接下来,按如下方式创建实体(触发通知):

curl localhost:1026/v2/entities -s -S -H 'Content-Type: application/json' -d @- <<EOF
{
  "id": "Device1",
  "type": "Device",
  "temperature": {
    "value": 23,
    "type": "Number"
  },
  "humidity": {
    "value": 99,
    "type": "Number"
  },
  "battery": {
    "value": 15,
    "type": "Number"  
  }
}
EOF

我在nc中得到的是:

POST /api/v1/telemetry HTTP/1.1
Host: localhost:1027
User-Agent: orion/2.4.0 libcurl/7.52.1
Fiware-Servicepath: /
Accept: application/json
Content-Length: 65
Content-Type: text/plain; charset=utf-8
Fiware-Correlator: 4ae608b0-d248-11ea-81de-000c29df7908
Ngsiv2-AttrsFormat: custom

[{ "temperature": "Device1", "humidity": "99", "battery": "15" }]

这是预期的结果,有替换。

接下来,重新启动监听进程并以这种方式更新实体(触发新通知):

curl localhost:1026/v2/entities/Device1/attrs?options=forcedUpdate -s -S -H 'Content-Type: application/json' -d @- <<EOF
{  
  "temperature": {
    "value": 32,
    "type": "Number"
  },
  "humidity": {
    "value": 79,
    "type": "Number"
  },
  "battery": {
    "value": 25,
    "type": "Number"  
  }
}
EOF

我现在进入 nc:

POST /api/v1/telemetry HTTP/1.1
Host: localhost:1027
User-Agent: orion/2.4.0 libcurl/7.52.1
Fiware-Servicepath: /
Accept: application/json
Content-Length: 65
Content-Type: text/plain; charset=utf-8
Fiware-Correlator: 66278dd8-d248-11ea-822d-000c29df7908
Ngsiv2-AttrsFormat: custom

[{ "temperature": "Device1", "humidity": "79", "battery": "25" }]

结论:根据我的测试,Orion 正常工作。

我建议您仔细查看上述步骤,并尝试找出与您的案例相比可能存在的任何差异。请注意订阅创建负载中的 $:需要它来避免 curl 中的 bash 变量替换。也许您正面临类似的问题?您可以使用 GET /v2/subscriptions 或直接在数据库(csubs 集合)中查看您的订阅情况。