首页 文章

Orion Context Broker Fiware中的订阅服务

提问于
浏览
2

我正在阅读有关OCB subscriptions的文档我不知道Python :(我是Java开发人员) . 我指的是Orion因订阅而发送的通知,您可以在属性 reference 中指明的服务

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

你能帮我吗?

提前致谢

1 回答

  • 2

    我建议你看一下Orion Context Broker User Manual,其中提供了有关HTTP动词,操作URL和参数的所有信息 .

    UPDATE :关于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中工作,但我想类似的方法是可行的 .

相关问题