【问题标题】:Having trouble with the user programers guide用户程序员指南有问题
【发布时间】:2015-04-08 08:58:13
【问题描述】:

我正在this site 上做练习。我完全按照这个例子,没有任何问题,直到我得到上下文订阅:

(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"
    ],
    "reference": "http://localhost:1028/accumulate",
    "duration": "P1M",
    "notifyConditions": [
        {
            "type": "ONTIMEINTERVAL",
            "condValues": [
                "PT10S"
            ]
        }
    ]
}
EOF

当我输入该代码时,我得到了预期的答案:

{
    "subscribeResponse": {
        "duration": "P1M",
        "subscriptionId": "51c04a21d714fb3b37d7d5a7"
    }
}

但是这句话让我很困惑:

如果你查看 accumulator-script.py 终端窗口,你会看到 每 10 收到一条类似于以下消息的消息 秒:

我在这里做的是输入这个命令:python accumulator-server.py 但我得到的输出(每 10 秒更新一次)是:127.0.0.1 - - [08/Apr/2015 10:52:56] "POST /accumulate HTTP/1.1" 200 -

我是否在这里遗漏了什么,因为我没有像教程中提到的那样获得预期的输出?

POST http://localhost:1028/accumulate
Content-Length: 492
User-Agent: orion/0.9.0
Host: localhost:1028
Accept: application/xml, application/json
Content-Type: application/json

{
  "subscriptionId" : "51c04a21d714fb3b37d7d5a7",
  "originator" : "localhost",
  "contextResponses" : [
    {
      "contextElement" : {
        "attributes" : [
          {
            "name" : "temperature",
            "type" : "float",
            "value" : "26.5"
          }
        ],
        "type" : "Room",
        "isPattern" : "false",
        "id" : "Room1"
      },
      "statusCode" : {
        "code" : "200",
        "reasonPhrase" : "OK"
      }
    }
  ]
}

我没有正确运行 python 脚本吗?顺便说一句,我对 python 和 linux 都很陌生...

【问题讨论】:

    标签: python linux fiware fiware-orion


    【解决方案1】:

    根据the manual,累加器的运行方式如下:

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

    【讨论】:

    • 是的,我只是来这里发布这个并说我想通了。谢谢...我只是有一个后续问题:假设脚本在另一台计算机上并且我正在通过 ssh 访问它?我可以在这里将本地主机更改为机器名称吗(curl localhost:1026/v1/updateContextSubscription -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d @- | python -mjson.tool)
    • 如果脚本在与 Orion 不同的主机上运行,​​那么您必须在订阅中正确设置 reference 字段,即不要使用“localhost:1028/accumulate”,而是使用正确的 IP/名称而不是“本地主机”。
    • 还有一个问题:例如在一个真正的企业应用程序中,提供的脚本是不是不够用?我不太确定这个脚本做了什么,除了它回答了吗?它甚至会在我的 mongoDB 中存储 room1 和 2 数据吗?例如,是否建议使用 cygnus 配置脚本以将订阅的数据存储在 mySQL DB 中?
    • accumulstor-server.py 脚本旨在用于学习和调试。它仅在标准输出中“在线”接收到通知消息时打印通知消息,它​​不会将通知信息存储在 DB 中或与任何其他外部系统交互,这可以使用 Cygnus 实现。如果您有更多问题(特别是与 Cygnus 相关的问题),我建议您将它们作为单独的 StackOverflow 问题发布。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    相关资源
    最近更新 更多