Azure / azure-iot-hub-python

Azure IoT Hub Data Plane Python SDK
MIT License
15 stars 11 forks source link

How to ask, using AMPQP over WebSockets, to an IoT Hub to send a Cloud To Device message with the Azure IoT Hub Service API Python SDK? #11

Open ghost opened 1 year ago

ghost commented 1 year ago

Can you, give a way to ask to an IoT Hub, located behind a firewall that only accept HTTPS/WebSockets (port 443) traffic and blocks AMQP (port 5671) and APQPS (port 5672), to send a Cloud To Device message?

The bellow schema shows where the issue is located (in surrounded HTTPS (443) between My Python Software using Azure IoT Hub Service API SDK and AZURE IoT Hub:

┌─────────────────────────────────────────────────┐
│ ┌─────────────────────┐                       ┌─┴─┐      ┌──────────────────┐
│ │ My Python Software  ├─<─── AMQPS (5671) ──>X│ F │      │  AZURE IoT Hub   │
│ │ using Azure Iot Hub ├─<─── AMQP  (5672) ──>X│ i │      │                  │
│ │ Service API SDK     │   ╔═══════════════╗   │ r │      │                  │
│ │                     ├─<─╫─ HTTPS (443) ─╫─>─│ e ├─<──>─┤                  │
│ └─────────────────────┘   ╚═══════════════╝   │ w │      └────────────────┬─┘
│                                               │ a │                       ^
│                                               │ l │                       │
│                                               │ l │                       v
│  Corporate Network                            └─┬─┘     ┌─────────────────┴─┐
└─────────────────────────────────────────────────┘    ┌──┤      Firewall     ├────┐
                                                       │  └─────────────────┬─┘    │
                                                       │    X       X       │      │
                                                       │    ^       ^       ^      │
                                                       │   MQTT   MQTTS    HTTPS   │
                                                       │  (1883)  (8883)   (443)   │
                                                       │    v       v       v      │
                                                       │ ┌──┴───────┴───────┴──┐   │
                                                       │ │ My Iot Device       ├┐  │
                                                       │ │ using Azure IoT Hub │├┐ │
                                                       │ │ Device API SDK      │││ │
                                                       │ └┬────────────────────┘││ │
                                                       │  └┬────────────────────┘│ │
                                                       │   └─────────────────────┘ │
                                                       │                           │
                                                       │ Customer Network          │
                                                       └───────────────────────────┘

The azure.iot.hub.IoTHubRegistryManager does have any constructor parameter to specify that we want to use AMQP Over WebSocket (GitHub link) when calling send_c2d_message (GitHub link).

Direct use of uamqp with uamqp.SendClient passing transport_type=uamqp.constants.TransportType.AmqpOverWebsocket in the constructor does not work either. Even if we specify that we want to use AMQP Over WebSocket (port 443), it uses AMQPS (port 5671) and it is certainly due to the format of the target passed to the constructor that should not start by "amqps://" like in the test_azure_event_hubs_send.py example (GitHub link). Can you please, give me what should be the target pattern when specifying AmqpOverWebsocket ?

On the other hand, the Azure IoT Hub Service API Java SDK works when using com.microsoft.azure.sdk.iot.service.messaging.IotHubServiceClientProtocol.AMQPS_WS as com.microsoft.azure.sdk.iot.service.messaging.MessagingClient constructor parameter (GitHub link).

Thanks for your help