Orion Context Broker Fiware 订阅服务

Service for subscription in Orion Context Broker Fiware

我正在阅读有关 OCB subscriptions 的文档,但我没有找到任何内容。只有一个 Python 示例,称为 accumulator.py(我不知道 Python :(,我是 Java 开发人员)。我将 Orion 发送的通知称为订阅的结果,您可以在属性 reference

中指明的服务

它是 GET 服务还是 POST?它需要任何参数吗?我正在编写一个带有参数的 REST GET 服务,即 Orion Context Broker 必须发送给我以更新我的应用程序的 JSON 字符串。正确吗??

你能帮帮我吗?

提前致谢

我建议您查看 Orion Context Broker User Manual,其中提供了有关 HTTP 动词、操作 URL 和参数的所有信息。

更新:关于 Orion 发送的通知,手册 includes some examples,例如:

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" : "51c0ac9ed714fb3b37d7d5a8",
  "originator" : "localhost",
  "contextResponses" : [
    {
      "contextElement" : {
        "attributes" : [
          {
            "name" : "temperature",
            "type" : "float",
            "value" : "26.5"
          }
        ],
        "type" : "Room",
        "isPattern" : "false",
        "id" : "Room1"
      },
      "statusCode" : {
        "code" : "200",
        "reasonPhrase" : "OK"
      }
    }
  ]
}

正如您在上面的片段中看到的,使用的动词是 POST(不是 GET)。因此,您应该准备代码监听通知以接收 URL 中的 POST 请求(在本例中 URL 是 /accumulate)并以这种方式处理负载你需要取决于你的应用程序。

例如Python可以使用装饰器(使用Flask框架):

@app.route('/accumulate', methods=['POST'])
def process_notification():
    # Do whatever you want with the request payload

我不知道 REST 服务器编程在 Java 中是如何工作的,但我想类似的方法是可能的。