fiware - 如何进行 Orion NGSIv2 订阅以通知 NGSIv1 中的 cygnus?

标签 fiware fiware-orion fiware-cygnus

编辑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 中,订阅注册正常(感谢评论中的提示),但我遇到了与 here 中所述相同的问题即使我使用 "attrsFormat":"legacy" 我做错了什么吗?为什么 Orion 不使用 ngsiv1 向 cygnus 发送通知?

The cygnus error trace.

天鹅座显示猎户座正在对此做出回应:

{
    "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"
        }
    }]
}

原始问题

正如 other question 中所述:

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.conditionsnotification 中)。

此外,请注意 callback不再使用。你必须使用:

"notification": {
  "http": {
    "url": "http://localhost:5050/notify"
  },
  ..
}

此外,如果您希望通知使用 NGSIv1 格式,则应包含 attrsFormat值为 legacy 的字段在notificationthe documentation 中所述.

最后注意,正确的操作URL是/v2/subscriptions ,不是/v1/subscriptions如您的示例所示。

编辑 1:考虑问题中编辑 1 部分中的新有效负载,请注意:

  • 您应该使用 attrs里面condition ,不是attributes (错误消息提示这一点)

  • 您应该使用 attrs里面notification ,不是attributes

  • 您应该使用 "q": "dFlag>0" (即查询字符串中没有空格)。查看 NGSIv2 specification 中的示例:

例如:

"expression": {
  "q": "temperature>40"
}

编辑 2: 1.2 之前的 Orion 版本使用 attrsFormat外面notification field 。因此,如果您使用 Orion 1.1,请尝试使用 "attrsFormat": "legacy"作为订阅负载 JSON 中的第一级字段。

关于fiware - 如何进行 Orion NGSIv2 订阅以通知 NGSIv1 中的 cygnus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37277048/

相关文章:

javascript - 使用 keyrock 验证测试 Web 应用程序时出现问题

postgresql - Fiware-Cygnus 配置到 Postgresql、DynamoDB 和 CKAN

mysql - Cygnus 不保留 MySql 数据库中的数据

linux - Centos 7 : Auto restart application if it stopped

fiware-orion - 如何让 rush 与我的 orionInstance 一起工作

fiware-orion - 列出所有实体资源功能似乎在 API v2 中失败

notifications - FIWARE-Orion Context Broker 元数据更新触发通知

fiware-cygnus - Cygnus Java 堆空间

ssh - 无法从 Orion 访问 Fiware Cosmos : Router has no route

fiware - 在固件中实现安全性