我使用的是Fiware-orionubuntu0.28,在我的本地主机上的ContextBroker 15.10 64位的dockerized版本。
$ 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 )文件开始--orion 0.28 with 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的原因。
发布于 2016-04-14 22:15:22
看起来答案就在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至少这个解决方案对我有效。
发布于 2016-04-14 21:39:42
您可能需要更改目标订阅的URL ( "reference“属性)。如果您在Docker中运行Orion,则Orion的本地主机是Docker本身,而不是您的机器。因此,通知被提升到Docker本地主机端口1028。由于可能不存在任何应用程序在Docker端口1028上进行侦听,因此会出现curl错误。
尝试在另一台计算机上设置累积服务器,或者创建到您计算机的本地主机的隧道(例如使用ngrok),并将订阅引用设置为该地址。
https://stackoverflow.com/questions/36624433
复制相似问题