我们正在使用docker实例中的Orion Context Broker,我们发现了一个可能的意外行为:
如果我们请求订阅不存在的实体,而不是返回错误,则创建订阅 .
这是预期的行为吗?
您可以通过执行以下请求来复制此问题:
curl -v localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' \
-d @- <<EOF
{
"description": "A subscription to a non-existent entity",
"subject": {
"entities": [
{
"id": "Non-existentEntity",
"type": "Room"
}
],
"condition": {
"attrs": [
"pressure"
]
}
},
"notification": {
"http": {
"url": "http://localhost:1028/accumulate"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
您应该收到带有订阅的 Location
标头的201创建的响应 . 在我们的案例中我们得到:
< HTTP/1.1 201 Created
< Connection: Keep-Alive
< Content-Length: 0
< Location: /v2/subscriptions/5811cbdd88beb7a40eead166
< Fiware-Correlator: 952a13b6-9c29-11e6-a352-0242ac110003
< Date: Thu, 27 Oct 2016 09:41:49 GMT
您可以检查订阅是否已创建,检索所有订阅:
curl localhost:1026/v2/subscriptions
或者使用 Location
标头中提供的URI直接检索它 . 在我们的情况下:
curl localhost:1026/v2/subscriptions/5811cbdd88beb7a40eead166
我们使用以下猎户座版本:
{
"orion" : {
"version" : "1.4.0-next",
"uptime" : "0 d, 0 h, 51 m, 21 s",
"git_hash" : "f541d9282c8039dd46b5284a772ff956a16b9512",
"compile_time" : "Thu Oct 20 07:51:10 UTC 2016",
"compiled_by" : "root",
"compiled_in" : "b99744612d0b"
}
}
1 回答
这是预期的行为 .
订阅和实体是独立的对象 . 这意味着您可以创建最初不包含任何实体的订阅,就像删除给定subscritpion所涵盖的所有实体不会导致订阅被删除一样 .
请注意,这是一个常见的用例,首先创建订阅作为系统的“引导”,然后开始运行实现实体创建动态的客户端应用程序 .