如何制作在 NGSIv1 中通知 cygnus 的 Orion NGSIv2 订阅?
How to make an Orion NGSIv2 subscription that notifies cygnus in NGSIv1?
编辑 2
curl --include \
--header 'Content-Type: application/json' \
--request POST \
--data-binary '{
"description": "Day subscription",
"subject": {
"entities": [
{
"idPattern": "es-leon-.*",
"type": "Event"
}
],
"condition": {
"attrs": [
"Title",
"dFlag"
],
"expression": {
"q": "dFlag>0"
}
}
},
"notification": {
"http": {
"url" : "http://localhost:5050/notify"
},
"attrs": [
"Title",
"dFlag"
],
"attrsFormat":"legacy"
}
}' \
'http://localhost:1026/v2/subscriptions'
在 Orion 中,订阅注册正常(感谢评论中的提示)但我遇到了与 中所述相同的问题,即使我使用 "attrsFormat":"legacy"
我做错了什么?为什么 orion 不使用 ngsiv1 向 cygnus 发送通知?
天鹅座显示猎户座正在回应:
{
"subscriptionId": "574315e77775f31b8d3da719",
"data": [{
"id": "es-leon-0",
"type": "Event",
"Title": {
"type": "none",
"value": "pepe",
"metadata": {}
},
"dFlag": {
"type": "text",
"value": "1",
"metadata": {}
}
}]
}
当它必须在 ngsiv1 中响应以下行时:
{
"subscriptionId": "5743178d7775f31b8d3da71a",
"originator": "localhost",
"contextResponses": [{
"contextElement": {
"type": "Event",
"isPattern": "false",
"id": "es-leon-0",
"attributes": [{
"name": "Title",
"type": "text",
"value": "pep"
}, {
"name": "dFlag",
"type": "text",
"value": "1"
}]
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}]
}
原题
如 中所述:
EDIT: note also that you can use NGSIv2 to create/update entities at
Orion and have notifications in NGSIv1 if you:
Create the subscription using NGSIv1 operations
Create the subscription using NGSIv2 operations with attrsFormat equal to legacy.
Have a look to more detailed information here.
所以我补了这个订阅:
curl --include \
--header 'Content-Type: application/json' \
--request POST \
--data-binary '{
"description": "Day subscription",
"subject": {
"entities": [
{
"idPattern": "es-leon-.*",
"type": "Event"
}
],
"condition": {
"attributes": [
"Title",
"dFlag"
],
"expression": {
"q": "dFlag > 0"
}
}
},
"notification": {
"callback": "http://localhost:5050/notify",
"attributes": [
"Title",
"dFlag"
]
}
}' \
'http://localhost:1026/v1/subscriptions'
但是 orion 不让我注册它并引发此错误:
HTTP/1.1 400 Bad Request
Connection: Keep-Alive
Content-Length: 67
Content-Type: application/json
Fiware-Correlator: 2ecdfc74-1c2f-11e6-82d7-000d3a23bf27
Date: Tue, 17 May 2016 12:59:25 GMT
{"error":"BadRequest","description":"no condition attrs specified"}
这是使用遗留属性的方式,以便它可以与带有 NGSIv2 的 cygnus 一起使用吗?
感谢您的帮助。
编辑 1:
根据回答,订阅应该是这样的:对吧?
curl --include \
--header 'Content-Type: application/json' \
--request POST \
--data-binary '{
"description": "Day subscription",
"subject": {
"entities": [
{
"idPattern": "es-leon-.*",
"type": "Event"
}
],
"condition": {
"attributes": [
"Title",
"dFlag"
],
"expression": {
"q": "dFlag > 0"
}
}
},
"notification": {
"http": {
"url" : "http://localhost:5050/notify"
},
"attributes": [
"Title",
"dFlag"
],
"attrsFormat":"legacy"
}
}' \
'http://localhost:1026/v2/subscriptions'
但我仍然收到错误消息:
HTTP/1.1 100 Continue
HTTP/1.1 400 Bad Request
Connection: Keep-Alive
Content-Length: 67
Content-Type: application/json
Fiware-Correlator: 60a0a1d2-1ddf-11e6-8bd6-000d3a23bf27
Date: Thu, 19 May 2016 16:33:11 GMT
{"error":"BadRequest","description":"no condition attrs specified"}
使用 attrs
而不是 attributes
(在 subject.conditions
和 notification
中)。
此外,请注意 callback
已不再使用。您必须使用:
"notification": {
"http": {
"url": "http://localhost:5050/notify"
},
..
}
此外,如果您希望通知使用 NGSIv1 格式,您应该在 notification
中包含值为 legacy
的 attrsFormat
字段,如 the documentation.[=34 中所述=]
最后,请注意,正确的操作 URL 是 /v2/subscriptions
,而不是您示例中显示的 /v1/subscriptions
。
EDIT 1: 考虑到问题中 EDIT 1 部分的新有效负载,请注意:
您应该在 condition
中使用 attrs
,而不是 attributes
(错误消息对此有抱怨)
您应该在 notification
中使用 attrs
,而不是 attributes
您应该使用 "q": "dFlag>0"
(即查询字符串中没有空格)。查看 NGSIv2 specification 中的示例:
例如:
"expression": {
"q": "temperature>40"
}
编辑 2: Orion 1.2 之前的版本在 notification
字段之外使用 attrsFormat
。因此,如果您使用的是 Orion 1.1,请尝试使用 "attrsFormat": "legacy"
作为订阅负载中的第一级字段 JSON.
编辑 2
curl --include \
--header 'Content-Type: application/json' \
--request POST \
--data-binary '{
"description": "Day subscription",
"subject": {
"entities": [
{
"idPattern": "es-leon-.*",
"type": "Event"
}
],
"condition": {
"attrs": [
"Title",
"dFlag"
],
"expression": {
"q": "dFlag>0"
}
}
},
"notification": {
"http": {
"url" : "http://localhost:5050/notify"
},
"attrs": [
"Title",
"dFlag"
],
"attrsFormat":"legacy"
}
}' \
'http://localhost:1026/v2/subscriptions'
在 Orion 中,订阅注册正常(感谢评论中的提示)但我遇到了与 "attrsFormat":"legacy"
我做错了什么?为什么 orion 不使用 ngsiv1 向 cygnus 发送通知?
天鹅座显示猎户座正在回应:
{
"subscriptionId": "574315e77775f31b8d3da719",
"data": [{
"id": "es-leon-0",
"type": "Event",
"Title": {
"type": "none",
"value": "pepe",
"metadata": {}
},
"dFlag": {
"type": "text",
"value": "1",
"metadata": {}
}
}]
}
当它必须在 ngsiv1 中响应以下行时:
{
"subscriptionId": "5743178d7775f31b8d3da71a",
"originator": "localhost",
"contextResponses": [{
"contextElement": {
"type": "Event",
"isPattern": "false",
"id": "es-leon-0",
"attributes": [{
"name": "Title",
"type": "text",
"value": "pep"
}, {
"name": "dFlag",
"type": "text",
"value": "1"
}]
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}]
}
原题
如
EDIT: note also that you can use NGSIv2 to create/update entities at Orion and have notifications in NGSIv1 if you:
Create the subscription using NGSIv1 operations
Create the subscription using NGSIv2 operations with attrsFormat equal to legacy. Have a look to more detailed information here.
所以我补了这个订阅:
curl --include \
--header 'Content-Type: application/json' \
--request POST \
--data-binary '{
"description": "Day subscription",
"subject": {
"entities": [
{
"idPattern": "es-leon-.*",
"type": "Event"
}
],
"condition": {
"attributes": [
"Title",
"dFlag"
],
"expression": {
"q": "dFlag > 0"
}
}
},
"notification": {
"callback": "http://localhost:5050/notify",
"attributes": [
"Title",
"dFlag"
]
}
}' \
'http://localhost:1026/v1/subscriptions'
但是 orion 不让我注册它并引发此错误:
HTTP/1.1 400 Bad Request
Connection: Keep-Alive
Content-Length: 67
Content-Type: application/json
Fiware-Correlator: 2ecdfc74-1c2f-11e6-82d7-000d3a23bf27
Date: Tue, 17 May 2016 12:59:25 GMT
{"error":"BadRequest","description":"no condition attrs specified"}
这是使用遗留属性的方式,以便它可以与带有 NGSIv2 的 cygnus 一起使用吗? 感谢您的帮助。
编辑 1:
根据回答,订阅应该是这样的:对吧?
curl --include \
--header 'Content-Type: application/json' \
--request POST \
--data-binary '{
"description": "Day subscription",
"subject": {
"entities": [
{
"idPattern": "es-leon-.*",
"type": "Event"
}
],
"condition": {
"attributes": [
"Title",
"dFlag"
],
"expression": {
"q": "dFlag > 0"
}
}
},
"notification": {
"http": {
"url" : "http://localhost:5050/notify"
},
"attributes": [
"Title",
"dFlag"
],
"attrsFormat":"legacy"
}
}' \
'http://localhost:1026/v2/subscriptions'
但我仍然收到错误消息:
HTTP/1.1 100 Continue
HTTP/1.1 400 Bad Request
Connection: Keep-Alive
Content-Length: 67
Content-Type: application/json
Fiware-Correlator: 60a0a1d2-1ddf-11e6-8bd6-000d3a23bf27
Date: Thu, 19 May 2016 16:33:11 GMT
{"error":"BadRequest","description":"no condition attrs specified"}
使用 attrs
而不是 attributes
(在 subject.conditions
和 notification
中)。
此外,请注意 callback
已不再使用。您必须使用:
"notification": {
"http": {
"url": "http://localhost:5050/notify"
},
..
}
此外,如果您希望通知使用 NGSIv1 格式,您应该在 notification
中包含值为 legacy
的 attrsFormat
字段,如 the documentation.[=34 中所述=]
最后,请注意,正确的操作 URL 是 /v2/subscriptions
,而不是您示例中显示的 /v1/subscriptions
。
EDIT 1: 考虑到问题中 EDIT 1 部分的新有效负载,请注意:
您应该在
condition
中使用attrs
,而不是attributes
(错误消息对此有抱怨)您应该在
notification
中使用attrs
,而不是attributes
您应该使用
"q": "dFlag>0"
(即查询字符串中没有空格)。查看 NGSIv2 specification 中的示例:
例如:
"expression": {
"q": "temperature>40"
}
编辑 2: Orion 1.2 之前的版本在 notification
字段之外使用 attrsFormat
。因此,如果您使用的是 Orion 1.1,请尝试使用 "attrsFormat": "legacy"
作为订阅负载中的第一级字段 JSON.