2

我遵循了关于天鹅座和猎户座的官方文档。所有通用启用程序都已正确部署,其日志文件中没有错误。但是奇怪的事情发生了,猎户座从来没有通知天鹅座。

为了测试这个机制,我按照官方文档中提供的 Car 实体示例进行了操作。

我的实体创建 bash 脚本:

(curl $1:1026/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
{
  "contextElements": [
    {
      "type": "Car",
      "isPattern": "false",
      "id": "Car1",
      "attributes": [
      {
        "name": "speed",
        "type": "integer",
        "value": "75"
      },
      {
        "name": "fuel",
        "type": "float",
        "value": "12.5"
      }
      ]
    }
  ],
  "updateAction": "APPEND"
}
EOF

我的实体订阅 bash 脚本:

(curl $1:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Fiware-Service: vehicles' --header 'Fiware-ServicePath: /4wheels' -d @- | python -mjson.tool) <<EOF
{
    "entities": [
        {
            "type": "Car",
            "isPattern": "false",
            "id": "Car1"
        }
    ],
    "attributes": [
        "speed",
        "oil_level"
    ],
    "reference": "http://$2:5050/notify",
    "duration": "P1M",
    "notifyConditions": [
        {
            "type": "ONCHANGE",
            "condValues": [
                "speed"
            ]
        }
    ],
    "throttling": "PT1S"
}
EOF

我的实体更新 bash 脚本:

(curl $1:1026/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
{
  "contextElements": [
    {
      "type": "Car",
      "isPattern": "false",
      "id": "Car1",
      "attributes": [
      {
        "name": "speed",
        "type": "integer",
        "value": $2
      }
      ]
    }
  ],
  "updateAction": "UPDATE"
}
EOF

注意:Orion 会响应所有请求。

执行完这些脚本后,cygnus 必须接收来自 orion 的上报信息并将其保存在数据库中,但没有任何反应。在 /var/log/cygnus/cygnus.log 文件或 /var/log/contextBroker/contextBroker.log 文件中都不会报告有关 orion 通知的任何信息。

注意:如果我使用官方文档中提供的 notify.sh 脚本,Cygnus 运行良好并将所有数据保存在数据库中。

注意:我在其他问题中阅读了有关开放端口的问题,但这些不适用于我的。

编辑 1

在我订阅猎户座后,回复是:

{
    "subscribeResponse": {
        "duration": "P1M",
        "subscriptionId": "563e12b4f4d8334d599753e0",
        "throttling": "PT1S"
    }
}

当我更新实体时,猎户座返回它:

{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "speed",
                        "type": "integer",
                        "value": ""
                    }
                ],
                "id": "Car1",
                "isPattern": "false",
                "type": "Car"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

要从 orion 获取实体,我使用了以下脚本:

(curl $1:1026/v1/queryContext -s -S --header 'Content-Type: application/json' \
    --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
{
    "entities": [
        {
            "type": "Car",
            "isPattern": "false",
            "id": "Car1"
        }
    ]
} 
EOF

回复:

{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "fuel",
                        "type": "float",
                        "value": "12.5"
                    },
                    {
                        "name": "speed",
                        "type": "integer",
                        "value": "123"
                    }
                ],
                "id": "Car1",
                "isPattern": "false",
                "type": "Car"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

注意速度值已成功更新。

4

1 回答 1

1

考虑到订阅请求中的Fiware-ServiceFiware-ServicePath头,已经在服务“vehicles”的“/4wheels”服务路径中执行。但是,实体创建请求不使用这样的头,所以它是在默认服务的默认服务路径(“/”)中创建的。因此,订阅没有“覆盖”实体,因此实体中的更新不会触发通知。

该问题的一种解决方案是在订阅的相同服务和服务路径中创建实体,即服务“车辆”的“/4wheels”服务路径。

请查看有关服务服务路径概念的 Orion 官方文档。

于 2015-11-10T14:21:57.193 回答