首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用dockerized fiware-orion订阅似乎不起作用

使用dockerized fiware-orion订阅似乎不起作用
EN

Stack Overflow用户
提问于 2016-04-14 21:21:01
回答 2查看 205关注 0票数 2

我使用的是Fiware-orionubuntu0.28,在我的本地主机上的ContextBroker 15.10 64位的dockerized版本。

代码语言:javascript
复制
$ 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配置是:

代码语言:javascript
复制
$ 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得到的警告是:

代码语言:javascript
复制
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 )文件开始--orion 0.28 with mongodb。然后我启动累加器

代码语言:javascript
复制
$ ./accumulator-server.py 1028 /accumulate localhost on
verbose mode is on
 * Running on http://localhost:1028/ (Press CTRL+C to quit)

然后我注册Room1

代码语言:javascript
复制
$ (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"
            }
        }
    ]
}

然后,我测试查询上下文以检查:

代码语言:javascript
复制
$ (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"
            }
        }
    ]
}

然后我做订阅

代码语言:javascript
复制
$ (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会说:

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

最后,我更新了实体,我应该在累加器上接收更新,但我没有:

代码语言:javascript
复制
$ (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的原因。

EN

回答 2

Stack Overflow用户

发布于 2016-04-14 22:15:22

看起来答案就在ifconfig上。

代码语言:javascript
复制
$ 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上。

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

代码语言:javascript
复制
$  ./accumulator-server.py 1028 /accumulate 172.17.0.1 on

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

代码语言:javascript
复制
(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

至少这个解决方案对我有效。

票数 3
EN

Stack Overflow用户

发布于 2016-04-14 21:39:42

您可能需要更改目标订阅的URL ( "reference“属性)。如果您在Docker中运行Orion,则Orion的本地主机是Docker本身,而不是您的机器。因此,通知被提升到Docker本地主机端口1028。由于可能不存在任何应用程序在Docker端口1028上进行侦听,因此会出现curl错误。

尝试在另一台计算机上设置累积服务器,或者创建到您计算机的本地主机的隧道(例如使用ngrok),并将订阅引用设置为该地址。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36624433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档