damienpontifex / azure-iot-sdk-rs

A rust library for connecting devices to Microsoft Azure IoT Hub
MIT License
14 stars 11 forks source link

Continue instead of breaking after a C2D message is processed. #39

Closed ghost closed 3 years ago

ghost commented 3 years ago

I think this fixes the issue I filed. Here is a trace showing multiple direct messages being received.

2020-11-13 22:17:14,705 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 49, 52, 46, 55, 48, 53, 53, 56, 56, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 51, 48, 46, 53, 52, 54, 52, 57, 52, 125], properties: {}, system_properties: {"$.mid": "422-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=422-t")
2020-11-13 22:17:15,703 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 49, 53, 46, 55, 48, 51, 51, 56, 49, 90, 34, 44, 34, 104, 117, 109, 105, 100, 105, 116, 121, 34, 58, 51, 56, 46, 57, 57, 53, 56, 56, 125], properties: {}, system_properties: {"$.mid": "169-h"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=169-h")
2020-11-13 22:17:16,706 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 49, 54, 46, 55, 48, 54, 55, 55, 51, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 50, 51, 46, 53, 57, 52, 51, 56, 125], properties: {}, system_properties: {"$.mid": "423-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=423-t")
2020-11-13 22:17:17,188 TRACE [azure_iot_sdk::mqtt_transport] Received PACKET PublishPacket(PublishPacket { fixed_header: FixedHeader { packet_type: PacketType { control_type: Publish, flags: 0 }, remaining_length: 40 }, topic_name: TopicName("$iothub/methods/POST/fooo1/?$rid=3"), packet_identifier: None, payload: [110, 117, 108, 108] })
2020-11-13 22:17:17,188 TRACE [azure_iot_sdk::mqtt_transport] PUBLISH ($iothub/methods/POST/fooo1/?$rid=3): Message { body: [110, 117, 108, 108], properties: {}, system_properties: {} }
2020-11-13 22:17:17,188 INFO  [dps_temp_client] Received direct method DirectMethodInvocation { method_name: "fooo1", message: Message { body: [110, 117, 108, 108], properties: {}, system_properties: {} }, request_id: "3" }
2020-11-13 22:17:17,188 TRACE [azure_iot_sdk::mqtt_transport] Responding to direct method with rid = 3
2020-11-13 22:17:18,706 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 49, 56, 46, 55, 48, 54, 51, 54, 48, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 50, 48, 46, 57, 57, 56, 52, 52, 55, 125], properties: {}, system_properties: {"$.mid": "424-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=424-t")
2020-11-13 22:17:20,707 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 50, 48, 46, 55, 48, 55, 53, 48, 57, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 50, 56, 46, 56, 51, 57, 54, 53, 55, 125], properties: {}, system_properties: {"$.mid": "425-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=425-t")
2020-11-13 22:17:20,708 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 50, 48, 46, 55, 48, 56, 48, 55, 56, 90, 34, 44, 34, 104, 117, 109, 105, 100, 105, 116, 121, 34, 58, 52, 48, 46, 53, 54, 54, 53, 53, 53, 125], properties: {}, system_properties: {"$.mid": "170-h"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=170-h")
2020-11-13 22:17:22,704 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 50, 50, 46, 55, 48, 52, 51, 52, 52, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 51, 54, 46, 51, 48, 51, 54, 51, 53, 125], properties: {}, system_properties: {"$.mid": "426-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=426-t")
2020-11-13 22:17:23,131 TRACE [azure_iot_sdk::mqtt_transport] Received PACKET PublishPacket(PublishPacket { fixed_header: FixedHeader { packet_type: PacketType { control_type: Publish, flags: 0 }, remaining_length: 39 }, topic_name: TopicName("$iothub/methods/POST/foo2/?$rid=4"), packet_identifier: None, payload: [110, 117, 108, 108] })
2020-11-13 22:17:23,131 TRACE [azure_iot_sdk::mqtt_transport] PUBLISH ($iothub/methods/POST/foo2/?$rid=4): Message { body: [110, 117, 108, 108], properties: {}, system_properties: {} }
2020-11-13 22:17:23,131 INFO  [dps_temp_client] Received direct method DirectMethodInvocation { method_name: "foo2", message: Message { body: [110, 117, 108, 108], properties: {}, system_properties: {} }, request_id: "4" }
2020-11-13 22:17:23,131 TRACE [azure_iot_sdk::mqtt_transport] Responding to direct method with rid = 4
2020-11-13 22:17:24,706 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 50, 52, 46, 55, 48, 54, 54, 56, 50, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 50, 54, 46, 54, 50, 48, 52, 56, 55, 125], properties: {}, system_properties: {"$.mid": "427-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=427-t")
2020-11-13 22:17:25,703 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 50, 53, 46, 55, 48, 51, 53, 54, 56, 90, 34, 44, 34, 104, 117, 109, 105, 100, 105, 116, 121, 34, 58, 52, 53, 46, 55, 51, 50, 54, 51, 125], properties: {}, system_properties: {"$.mid": "171-h"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=171-h")
2020-11-13 22:17:26,705 TRACE [azure_iot_sdk::mqtt_transport] Sending message Message { body: [123, 34, 116, 105, 109, 101, 115, 116, 97, 109, 112, 34, 58, 34, 50, 48, 50, 48, 45, 49, 49, 45, 49, 52, 84, 48, 54, 58, 49, 55, 58, 50, 54, 46, 55, 48, 53, 51, 57, 56, 90, 34, 44, 34, 116, 101, 109, 112, 101, 114, 97, 116, 117, 114, 101, 34, 58, 49, 55, 46, 49, 48, 48, 54, 55, 125], properties: {}, system_properties: {"$.mid": "428-t"} } to topic TopicName("devices/edb126bb-51a2-4154-8172-707f19ffce3b-DE/messages/events/%24.mid=428-t")

Note that unlike before, the message loop keeps running, etc.

ghost commented 3 years ago

I also exposed the ping method to the client. If you want, I can open a separate PR for that.

damienpontifex commented 3 years ago

Thanks again @basusamit

damienpontifex commented 3 years ago

Included in release 0.6.0