FIWARE Orion:在订阅有效负载中使用查询字符串

时间:2017-04-07 16:18:08

标签: fiware-orion

目前Orion禁止使用'='标志: http://fiware-orion.readthedocs.io/en/1.5.0/user/forbidden_characters/index.html

但这会阻止使用查询字符串进行订阅:

$ (curl broker.waziup.io/v1/subscribeContext -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' --header 'Fiware-Service:waziup' --header 'Fiware-ServicePath:/TEST' -d @- | python -mjson.tool) <<EOF
{
    "entities": [
        {
            "type": "SensingDevice",
            "isPattern": "false",
            "id": "Sensor1"
        }
    ],
    "attributes": [
        "temperature"
    ],
    "reference": "http://localhost/v1/sms/send?contact=0039&msg=Sensor1",
    "duration": "P1M",
    "notifyConditions": [
        {
            "type": "ONCHANGE",
            "condValues": [
                "temperature"
            ]
        }
    ],
    "throttling": "PT1S"
}
EOF

结果:

{
    "subscribeError": {
        "errorCode": {
            "code": "400",
            "details": "Illegal value for JSON field",
            "reasonPhrase": "Bad Request"
        }
    }
}

查询字符串用于将参数传递给回调服务器(我没有看到其他方法)。 有什么方法吗?

1 个答案:

答案 0 :(得分:1)

根据NGSIv2中的自定义通知,有一种在通知URL中设置查询参数的方法。查看&#34;自定义通知&#34; NGSIv2 specification中的部分。

您正在进行的订阅将是这样的:

POST /v2/subscriptions
...

{
  "subject": {
    "entities": [
      {
        "id": "Sensor1",
        "type": "SensingDevice"
      }
    ],
    "condition": {
      "attrs": [ "temperature" ]
    }
  },
  "notification": {
    "httpCustom": {
      "url": "http://localhost/v1/sms/send",
      "qs": {
        "contact": "0039",
        "msg": "Sensor1"
      }
    },
    "attrs": [ "temperature"]
  },
  "expires": "2016-05-07T18:30:00.00Z",
  "throttling": 1
}

请注意,您甚至可以使用模板概括所有传感器的订阅,方法如下:

POST /v2/subscriptions
...

{
  "subject": {
    "entities": [
      {
        "idPattern": "Sensor.*",
        "type": "SensingDevice"
      }
    ],
    "condition": {
      "attrs": [ "temperature" ]
    }
  },
  "notification": {
    "httpCustom": {
      "url": "http://localhost/v1/sms/send",
      "qs": {
        "contact": "0039",
        "msg": "${id}"
      }
    },
    "attrs": [ "temperature"]
  },
  "expires": "2016-05-07T18:30:00.00Z",
  "throttling": 1
}