使用FIWARE Orion Context Broker API V2创建订阅报错,请求协助排查
解决NGSI v2订阅创建时的"no condition attributes specified"错误
我来帮你分析这个问题,其实根源是NGSI v2和v1的订阅规则存在差异,你的请求不符合v2的逻辑要求。
问题出在哪?
看你的订阅请求:
- 你在
subject.condition.attrs里指定了只监听pressure属性的变化 - 但在
notification.attrs里却要求返回temperature属性
在NGSI v2的规则中,当你通过condition.attrs过滤了要监听的属性时,通知里请求的属性必须是这个过滤集合的子集——简单说就是,你只能要求返回你正在监听变化的那些属性。你的请求里两者完全不重叠,系统就判定为“没有指定有效的条件属性”,返回400错误。而v1对这个逻辑的限制更宽松,所以能正常执行。
修正方案(二选一即可)
方案1:让通知属性和监听属性匹配
把notification.attrs改成和condition.attrs一致的属性,比如:
curl -v localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' -d @- <<EOF { "description": "A subscription to get info about Room1", "subject": { "entities": [ { "id": "Room10", "type": "Room" } ], "condition": { "attrs": ["pressure"] } }, "notification": { "http": { "url": "http://localhost:1028/publish" }, "attrs": ["pressure"] # 这里改成和condition一致的属性 }, "expires": "2040-01-01T14:00:00.00Z", "throttling": 5 } EOF
方案2:去掉条件过滤(如果不需要只监听特定属性)
如果你不需要只监听pressure的变化,而是只要实体有任何属性变化就通知temperature,可以删除condition部分:
curl -v localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' -d @- <<EOF { "description": "A subscription to get info about Room1", "subject": { "entities": [ { "id": "Room10", "type": "Room" } ] }, "notification": { "http": { "url": "http://localhost:1028/publish" }, "attrs": ["temperature"] }, "expires": "2040-01-01T14:00:00.00Z", "throttling": 5 } EOF
补充说明
NGSI v2的设计更注重逻辑一致性:当你指定监听特定属性的变化时,意味着你只关心这些属性的更新,所以通知里只能请求这些属性。而v1允许“监听A属性变化,返回B属性”的场景,这是两个版本的核心差异之一。
内容的提问来源于stack exchange,提问作者asolleiro
相关产品推荐
相关产品推荐

