fiware - 使用 dockerized fiware-orion 似乎无法进行订阅

标签 fiware fiware-orion

我正在使用 Fiware-Orion ContextBroker 0.28,这是 ubuntu 15.10 64 位上的本地主机中的 Docker 化版本。

$ curl localhost:1026/version
{
  "orion" : {
  "version" : "0.28.0-next",
  "uptime" : "0 d, 0 h, 0 m, 6 s",
  "git_hash" : "067e13618c247daa4af61f82d7831f3015d9eb5d",
  "compile_time" : "Mon Mar 14 13:04:02 UTC 2016",
  "compiled_by" : "root",
  "compiled_in" : "838a42ae8431"
}
}

我使用的docker配置是:

$ cat docker-compose.yml 
mongo:
  image: mongo:2.6
  command: --smallfiles --nojournal
orion:
  image: fiware/orion
  links:
    - mongo
  ports:
    - "1026:1026"
  command: -dbhost mongo

当我订阅时,我从 orion/docker 收到的警告是:

orion_1 | WARNING@12:19:14  AlarmManager.cpp[303]: Raising alarm NotificationError localhost:1028/accumulate: (curl_easy_perform failed: Couldn't connect to server)

我正在关注 API V1 walkthorugh测试对更改的订阅。我从一个全新的 dockerized(sudo docker-compose up 和所有这些模糊)fiware-orion 0.28 和 mongodb 开始。然后我启动累加器

$ ./accumulator-server.py 1028 /accumulate localhost on
verbose mode is on
 * Running on http://localhost:1028/ (Press CTRL+C to quit)

然后我注册 Room1

$ (curl localhost:1026/v1/updateContext -s -S --header 'Content-Type: application/json' \
>     --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
> {
>     "contextElements": [
>         {
>             "type": "Room",
>             "isPattern": "false",
>             "id": "Room1",
>             "attributes": [
>                 {
>                     "name": "temperature",
>                     "type": "float",
>                     "value": "23"
>                 },
>                 {
>                     "name": "pressure",
>                     "type": "integer",
>                     "value": "720"
>                 }
>             ]
>         }
>     ],
>     "updateAction": "APPEND"
> } 
> EOF
{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "temperature",
                        "type": "float",
                        "value": ""
                    },
                    {
                        "name": "pressure",
                        "type": "integer",
                        "value": ""
                    }
                ],
                "id": "Room1",
                "isPattern": "false",
                "type": "Room"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

然后我测试查询上下文只是为了检查:

$ (curl localhost:1026/v1/queryContext -s -S --header 'Content-Type: application/json' \
>     --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
> {
>     "entities": [
>         {
>             "type": "Room",
>             "isPattern": "false",
>             "id": "Room1"
>         }
>     ]
> } 
> EOF
{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "pressure",
                        "type": "integer",
                        "value": "720"
                    },
                    {
                        "name": "temperature",
                        "type": "float",
                        "value": "23"
                    }
                ],
                "id": "Room1",
                "isPattern": "false",
                "type": "Room"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

然后我订阅

$ (curl localhost:1026/v1/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": [
>         "pressure"
>     ],
>     "reference": "http://localhost:1028/accumulate",
>     "duration": "P1M",
>     "notifyConditions": [
>         {
>             "type": "ONCHANGE",
>             "condValues": [
>                 "pressure"
>             ]
>         }
>     ],
>     "throttling": "PT5S"
> }
> EOF
{
    "subscribeResponse": {
        "duration": "P1M",
        "subscriptionId": "570f8ac247fcf8a62722353c",
        "throttling": "PT5S"
    }
}

此时,手册说累加器可能会收到第一次更新,但这不是必需的,所以我什么也没有收到,但也许没关系。或者也许不是,因为发送订阅查询后,orion 的 docker 会说:

orion_1 | WARNING@12:19:14  AlarmManager.cpp[303]: Raising alarm NotificationError localhost:1028/accumulate: (curl_easy_perform failed: Couldn't connect to server)

最后我更新了实体,我应该收到累加器的更新,但我没有:

$ (curl localhost:1026/v1/updateContext -s -S --header 'Content-Type: application/json' \
>      --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
> {
>     "contextElements": [
>         {
>             "type": "Room",
>             "isPattern": "false",
>             "id": "Room1",
>             "attributes": [
>                 {
>                     "name": "temperature",
>                     "type": "float",
>                     "value": "56.5"
>                 },
>                 {
>                     "name": "pressure",
>                     "type": "integer",
>                     "value": "553"
>                 }
>             ]
>         }
>     ],
>     "updateAction": "UPDATE"
> } 
> EOF
{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "temperature",
                        "type": "float",
                        "value": ""
                    },
                    {
                        "name": "pressure",
                        "type": "integer",
                        "value": ""
                    }
                ],
                "id": "Room1",
                "isPattern": "false",
                "type": "Room"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

我还应该说,在 Ubuntu 上编译 fiware-orion 相当困难,这就是我使用 docker 的原因。

最佳答案

看起来答案就在 ifconfig 上。

$ ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:09:7b:6e:b7  
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:9ff:fe7b:6eb7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1036 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1506 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0

这意味着对于 docker orion 机器,主机位于 172.17.0.1。

累加器应以以下方式启动:

$  ./accumulator-server.py 1028 /accumulate 172.17.0.1 on

订阅命令应该类似于(使用“reference”:“http://172.17.0.1:1028/accumulate”):

(curl localhost:1026/v1/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",
        "pressure"
    ],
    "reference": "http://172.17.0.1:1028/accumulate",
    "duration": "P1M",
    "notifyConditions": [
        {
            "type": "ONCHANGE",
            "condValues": [
                 "temperature",
                 "pressure"
            ]
        }
    ],
    "throttling": "PT1S"
}
EOF

至少这个解决方案对我有用

关于fiware - 使用 dockerized fiware-orion 似乎无法进行订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36624433/

相关文章:

fiware - 如何在 Orion Context Broker NGSIv2 上创建高级订阅表达式?

fiware - Orion 订阅不会检测实体的删除

fiware - 取消 Cygnus 订阅

mysql - 如何使用cygnus在MySql中存储数据?

FIWARE:Orion Context Broker 和 CKAN

FIWARE物联网代理: how to send the location attribut to the contextBroker Entity?

fiware-orion - 列出所有实体资源功能似乎在 API v2 中失败

java - 质子 CEP : 100% CPU usage after a few hours

fiware - Orion 上下文代理,订阅格式 "JSON"

android - 使用 Android 客户端的 Orion Context Broker 上下文订阅