我正在使用Fiware-Orion ContextBroker 0.28,我的本地主机上的dockerized版本在ubuntu 15.10 64位上 .
$ 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 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上进行编译是很困难的,这也是我使用docker的原因 .
2 回答
它看起来像ifconfig上的答案 .
这意味着对于docker orion机器,主机在172.17.0.1上 .
累加器应该以:
订阅命令应该类似于(使用"reference":“http://172.17.0.1:1028/accumulate”):
至少这个解决方案适合我
您可能必须更改目标订阅的URL(“引用”属性) . 如果你在Docker中运行Orion,那么Orion的localhost就是Docker本身,而不是你的机器 . 因此,通知被提升到Docker localhost端口1028.由于可能不存在任何侦听Docker端口1028的应用程序,因此会出现curl错误 .
尝试在另一台计算机中设置累积服务器,或者 Build 到计算机的localhost的隧道(例如使用ngrok),并将订阅引用设置为该地址 .