Reputation: 1990
I'm using Azure IoT Hub with a C# desktop application client. I introduced a new Direct Method invocation on the server and also added a handler to a new client version. But I'm wondering what would happen to old clients that do not have a handler for this direct method if I publish the changes to the backend.
Would this result in an exception and so a crash or would the invocation be ignored? I tried searching for answers to this question here on SO and elsewhere but couldn't find any answers.
Upvotes: 1
Views: 1751
Reputation: 8255
Have a look at the document: Handle a direct method on device.
UPDATE:
The following cases show examples of all responses on invoking a device direct method using a REST POST:
https://xxxxxxxx.azure-devices.net/twins/myDevice6/methods?api-version=2018-06-30
payload:
{
"methodName": "writeLine",
"responseTimeoutInSeconds": 10,
"payload": {
"input1": 12345,
"input2": "HelloDevice"
}
}
Response 1: Device is not connected
{
"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": ""
}
Response 2: Device is connected and no subscribed
{
"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": ""
}
Response 3: Device is subscribed for another methodName e.g. $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": ""
}
Response 4: Device is subscribed for specific methodName but no response e.g. $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": ""
}
Response 5: Device is subscribed for any methodName, but no response e.g. $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": ""
}
Basically, your cases can be the Response 3. or Response 5.
Probably your client application is using the Azure IoT C# SDK, where the MQTTTransportHandler class has a property methodPostTopicFilter = "$iothub/methods/POST/#", so your response is #5 should be with an errorCode = 504, but the device SDK is generating an errorCode = 501 as a response for not implemented handler (publishing on topic $iothub/methods/res/501/?$rid={requestId}).
Note, that the response time is defined by invoker, see a property responseTimeoutInSeconds in the payload body. In the case of Response 3. the response time is ~5 seconds.
Upvotes: 1