如果没有处理程序,Azure IoT中心直接方法调用会怎样?

时间:2019-06-17 12:21:05

标签: c# azure azure-iot-hub

我正在将Azure IoT中心与C#桌面应用程序客户端一起使用。我在服务器上引入了新的直接方法调用,还向新的客户端版本添加了处理程序。 但是我想知道如果我将更改发布到后端,那些没有此直接方法处理程序的旧客户端会发生什么情况。

这是否会导致异常,从而导致崩溃或将忽略调用? 我尝试在SO或其他位置搜索此问题的答案,但找不到任何答案。

2 个答案:

答案 0 :(得分:2)

它将被忽略并向调用者返回501错误。

答案 1 :(得分:1)

看看文档:{​​{3}}。

更新:

以下情况显示了有关使用REST POST调用设备直接方法的所有响应的示例:

https://xxxxxxxx.azure-devices.net/twins/myDevice6/methods?api-version=2018-06-30

有效载荷:

{
  "methodName": "writeLine",
  "responseTimeoutInSeconds": 10,
  "payload": {
    "input1": 12345,
    "input2": "HelloDevice"
    }
}

响应1:设备未连接

{
  "Message": "{\"errorCode\":404103,\"trackingId\":\"e796f79f02094184ba375533dd522b62-TimeStamp:06/18/2019 06:08:11\",\"message\":\"Timed out waiting for device to connect.\",\"info\":{\"timeout\":\"00:00:00\"},\"timestampUtc\":\"2019-06-18T06:08:11.1216684Z\"}",
  "ExceptionMessage": ""
}

响应2:设备已连接且未订阅

{
  "Message": "{\"errorCode\":404103,\"trackingId\":\"4d2c65b6fd994fc5adc902ecfade1877-G:3-TimeStamp:06/18/2019 06:11:52-G:11-TimeStamp:06/18/2019 06:11:52\",\"message\":\"Timed out waiting for device to subscribe.\",\"info\":{},\"timestampUtc\":\"2019-06-18T06:11:52.6039066Z\"}",
  "ExceptionMessage": ""
}

响应3:设备已订阅另一种方法名,例如 $ iothub / methods / POST / xyz /#

{
  "Message": "{\"errorCode\":404103,\"trackingId\":\"59df13ecc3a04d63b7a1813ed9e6187f-G:3-TimeStamp:06/18/2019 06:14:48-G:10-TimeStamp:06/18/2019 06:14:48\",\"message\":\"Timed out waiting for device to subscribe.\",\"info\":{},\"timestampUtc\":\"2019-06-18T06:14:48.110565Z\"}",
  "ExceptionMessage": ""
}

响应4:为设备预订了特定的methodName,但没有响应,例如 $ iothub / methods / POST / writeLine /#

{
  "Message": "{\"errorCode\":504101,\"trackingId\":\"1692ee301e344215945385b282fd0b78-G:3-TimeStamp:06/18/2019 06:16:48-G:12-TimeStamp:06/18/2019 06:16:48\",\"message\":\"Timed out waiting for the response from device.\",\"info\":{},\"timestampUtc\":\"2019-06-18T06:16:48.628664Z\"}",
  "ExceptionMessage": ""
}

响应5:设备已订阅任何methodName,但没有响应,例如 $ iothub / methods / POST /#

{
  "Message": "{\"errorCode\":504101,\"trackingId\":\"7edc4ecfc095424c9a378a2e064bc886-G:3-TimeStamp:06/18/2019 06:59:24-G:16-TimeStamp:06/18/2019 06:59:24\",\"message\":\"Timed out waiting for the response from device.\",\"info\":{},\"timestampUtc\":\"2019-06-18T06:59:24.0184557Z\"}",
  "ExceptionMessage": ""
}

基本上,您的案例可以是响应3或响应5。

您的客户端应用程序可能正在使用Azure IoT C#SDK,其中 MQTTTransportHandler 类具有属性 methodPostTopicFilter =“ $ iothub / methods / POST /#” 您的响应是#5应该是errorCode = 504,但是设备SDK 正在生成errorCode = 501作为未实现的处理程序的响应(在主题 $ iothub / methods / res上发布/ 501 /?$ rid = {requestId} )。

请注意,响应时间是由调用者定义的,请参见有效负载正文中的属性 responseTimeoutInSeconds 。对于响应3,响应时间约为5秒。