1

我正在“用户和程序员指南”中尝试示例,但订阅后我没有收到任何通知。更新和查询运行良好。“receptor”脚本就是这样启动的

./accumulator-server.py 1028 /accumulate on

它似乎启动并运行

verbose mode is on
 * Running on http://0.0.0.0:1028/ 

然后订阅似乎也可以

(curl localhost:1026/NGSI10/subscribeContext -s -S --header 'Content-Type: application/json' --      header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
{
    "entities": [
        {
        "type": "Room",
        "isPattern": "false",
        "id": "Room1"
    }
],
"attributes": [
    "temperature"
],
"reference": "http://localhost:1028/accumulate",
"duration": "P1M",
"notifyConditions": [
        {
            "type": "ONTIMEINTERVAL",
            "condValues": [
                "PT10S"
            ]
        }
    ]
    }
   EOF

回复:

{
    "subscribeResponse": {
    "duration": "P1M", 
    "subscriptionId": "535e558d28604367380deb5c"
    }
}

然后,Room1 的更新

curl  -v localhost:1026/NGSI10/updateContext --header 'Content-Type: application/json' --header 'Accept: application/json' -d @-  <<EOF
> {
>     "contextElements": [
>         {
>             "type": "Room",
>             "isPattern": "false",
>             "id": "Room1",
>             "attributes": [
>             {
>                 "name": "temperature",
>                 "type": "centigrade",
>                 "value": "x"
>             },
>             {
>                 "name": "pressure",
>                 "type": "mmHg",
>                 "value": "x"
>             }
>             ]
>         }
>     ],
>     "updateAction": "UPDATE"
> }
> EOF
* About to connect() to localhost port 1026 (#0)
*   Trying ::1... connected
* Connected to localhost (::1) port 1026 (#0)
> POST /NGSI10/updateContext HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: localhost:1026
> Content-Type: application/json
> Accept: application/json
> Content-Length: 454
> 
< HTTP/1.1 200 OK
< Content-Length: 513
< Content-Type: application/json
< Date: Mon, 28 Apr 2014 12:08:38 GMT
< 
{
  "contextResponses" : [
    {
      "contextElement" : {
        "type" : "Room",
        "isPattern" : "false",
        "id" : "Room1",
        "attributes" : [
          {
            "name" : "temperature",
            "type" : "centigrade",
            "value" : ""
          },
          {
            "name" : "pressure",
            "type" : "mmHg",
            "value" : ""
          }
        ]
      },
      "statusCode" : {
        "code" : "200",
        "reasonPhrase" : "OK"
      }
    }
  ]
}
* Connection #0 to host localhost left intact
* Closing connection #0

但是在accumulator-server's 的输出中没有显示任何内容

知道我做错了什么吗?

4

1 回答 1

0

这实际上是由于用户手册中的“文档错误”。

从 0.10.0 版本开始,Orion Context Broker 能够在 IPv4 和 IPv6 中发送通知,并且 subscribeContext 操作中引用元素中使用的“localhost”倾向于被操作系统解析为 IPv6。因此,默认情况下,通知在 IPv6 中发送,但如果累加器服务器使用

./accumulator-server.py 1028 /accumulate on

然后它只听 IPv4。

accumulator-server.py 允许在命令行中指定列表地址,因此如果您使用以下命令指定 ::1(IPv6 的本地主机)

./accumulator-server.py 1028 /accumulate ::1 on

那么它应该可以正常工作。以下输出证实了这一点:

verbose mode is on
* Running on http://[::1]:1028/
* Restarting with reloader
verbose mode is on

(注意上面“Running on”行中的 ::1,与纯 IPv4 情况的 0.0.0.0 不同)

感谢您的反馈,用户手册已得到修复,现在它使用了正确的命令 :)

于 2014-04-29T14:05:23.477 回答