我正在阅读有关 OCB subscriptions 的文档我什么也没找到。只有一个 Python 示例,称为 Accumulator.py(我不懂 Python :(,我是 Java 开发人员)。我指的是 Orion 作为订阅结果发送的通知,您可以在属性中指示的服务引用
它是 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 中是如何工作的,但我想类似的方法是可能的。
关于rest - Orion Context Broker 固件中的订阅服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29295383/