Leaving Azure IoT Hub is a different job from swapping one MQTT broker for another. IoT Hub accepts MQTT connections from devices, but it only lets them use its own topics, it has no retained messages, and your backends never touch MQTT at all: they read telemetry from an Event Hubs-compatible endpoint and send commands through the service SDK. Every one of those pieces has to be translated, and the device side usually needs a firmware release.
azure-iot-hub-migration-skills turns that translation into a repeatable process. It contains two AI agent skills and a set of scripts that let Claude Code, Claude.ai or another agent that reads SKILL.md files plan an Azure IoT Hub migration to ConnectMQ and then carry it out, with a relay that keeps both platforms in sync until the last device has moved. This post walks through how it works.
Why an Azure IoT Hub Migration Needs Its Own Playbook
With Mosquitto or EMQX, the old and new brokers speak the same language: you bridge them and move clients. IoT Hub breaks that assumption in three places:
- Fixed device topics. Telemetry goes to
devices/{deviceId}/messages/events/, commands arrive ondevices/{deviceId}/messages/devicebound/#, and twins and direct methods live under$iothub/. On a standard broker you design your own topic tree, and$topics are reserved for the broker. - Platform services instead of broker features. Device twins, direct methods, cloud-to-device feedback, message routing and the Device Provisioning Service are IoT Hub services. They need replacements built from MQTT primitives such as retained messages and the request/response pattern.
- No MQTT on the backend side. Consumers use Event Hubs consumer groups and the service SDK, so backend code changes as much as device code.
The skills are built around these differences instead of pretending IoT Hub is just another broker.
What Is in the Repository?
| Skill | Use it for |
|---|---|
azure-iot-hub-migration-planner |
Registry and twin inventory, Azure Monitor sizing, topic redesign, client IDs and ACL rules, backend replacement list, written plan |
azure-iot-hub-migration-executor |
ConnectMQ checks, twins as retained state, Event Hubs relay, backend switch, device waves, rollback, decommissioning |
Both skills share a reference file describing the target: ConnectMQ endpoints, how generated credentials and issued client IDs work, the access control model, plan limits and MQTT reason codes. The agent plans against those facts rather than guessing.
Planning: From Device Registry to Topic Map
The planner begins with exports you can produce with the Azure CLI and its azure-iot extension: the device registry (az iot hub device-identity list), the twins (az iot hub query -q "SELECT * FROM devices"), the message routes and the hub's tier. It then runs the device converter:
python scripts/azure_devices_to_connectmq.py devices.json --out migration/
The report counts devices by authentication type and status and calls out the two classic blockers. X.509 devices, whether self-signed or CA-signed, need firmware that can send a username and password, because ConnectMQ authenticates with credentials over TLS. IoT Edge devices need a replacement for the Edge runtime, such as a local broker that bridges to ConnectMQ. Devices using SAS tokens are the easy case: the token becomes a fixed password and the refresh logic goes away.
Next comes sizing. The planner reads a week of Azure Monitor metrics, including connectedDeviceCount for peak connections and d2c.telemetry.ingress.success for message rates, and samples real payloads with az iot hub monitor-events. Connections, session minutes and retained messages are checked separately against the ConnectMQ plans. That matters because 600 always-on devices fit Scale's connection limit but use far more session minutes than its monthly allowance.
The New Topic Scheme
The heart of the plan is a topic map. The skill proposes a scheme that keeps the Azure deviceId in every topic, so backends do not need an ID translation table:
| IoT Hub | ConnectMQ |
|---|---|
devices/{id}/messages/events/ |
devices/{id}/telemetry |
devices/{id}/messages/devicebound/# |
devices/{id}/commands/{name} |
$iothub/twin/PATCH/properties/reported/ |
devices/{id}/twin/reported (retained) |
$iothub/twin/PATCH/properties/desired/# |
devices/{id}/twin/desired (retained) |
$iothub/methods/POST/{method}/ |
devices/{id}/methods/{method}/req |
$iothub/methods/res/{status}/ |
devices/{id}/methods/{method}/res |
Twins become retained documents, so a device that wakes up gets its desired state without a separate GET request. Direct methods become MQTT 5 request/response with a response topic and correlation data. IoT Hub's property bags move into the payload or into MQTT 5 user properties. The same scheme feeds the generated ACL rules: each device may publish its own telemetry and reported twin, and subscribe to its own commands, desired twin and method requests, while a backend credential gets access to the whole devices/# tree.
Because ConnectMQ client IDs carry the credential's issued prefix (c7f3k2_sensor-0042), the planner builds a client map with client_id_map.py. It then re-runs the converter so that rules match the new client ID while topics keep the old deviceId.
Executing: Relay, Backends, Devices
Twins as Retained State
Right before the parallel run, the executor exports the twins again and converts them:
python scripts/azure_twins_to_retained.py twins.json -o migration/twins-retained.json --skip-empty
python scripts/copy_retained.py --import migration/twins-retained.json --target mqtts://BROKER_HOST:8883
IoT Hub's $metadata and $version bookkeeping is stripped, module twins are reported separately, and payloads above the plan's message size are flagged. If you already model state this way, see digital twins with retained MQTT messages.
The Event Hubs Relay
Since IoT Hub cannot bridge to another broker, the repository ships eventhub_relay.py. It reads the Event Hubs-compatible endpoint with a dedicated consumer group, takes the device ID from the iothub-connection-device-id system property, and publishes each message to devices/{id}/telemetry on ConnectMQ at QoS 1. Application properties become user properties, and an optional blob checkpoint store makes restarts safe. Only checkpoints for messages ConnectMQ has acknowledged are written.
With the relay running, every device looks the same on ConnectMQ whether it has moved or not.
Backends Before Devices
The executor then moves backends one at a time. An Event Hubs consumer becomes a worker on a shared subscription. A routing rule into Service Bus or Cosmos DB becomes a worker that writes to the same destination. send_c2d_message becomes a QoS 1 publish, and invoke_device_method becomes a request on the method topic. Each new backend runs in shadow mode next to the old one before the switch. For commands sent while some devices are still on IoT Hub, the skill describes a small reverse worker built on the IoT Hub service SDK.
Device Waves and Rollback
Topics change, so devices need new firmware or configuration. The recommended pattern is firmware that carries both connection profiles, with ConnectMQ as primary and IoT Hub as fallback, and a flag that selects the active one. A wave flips the flag for a group of devices; a rollback flips it back. Non-secret settings can travel in a twin desired property, but the skill advises sending passwords through a C2D message or direct method rather than storing them in the twin. DPS cannot help here, because it only assigns devices to IoT Hubs.
Before every wave the executor runs a go/no-go checklist. It sizes the wave against the plan's connection rate and watches for reason codes such as 0x85 (bare deviceId used as client ID), 0x86 (old SAS credentials) and 0x87 (old IoT Hub topics hitting the ACL). Identities stay in IoT Hub, disabled rather than deleted, until the rollback window closes.
Installing the Skills
In Claude Code:
/plugin marketplace add connectmq/azure-iot-hub-migration-skills
/plugin install azure-iot-hub-migration-skills@connectmq-azure-iot-hub-migration
You can also copy the skills/ folders into ~/.claude/skills/, or zip a skill folder and upload it to Claude.ai. The converters use only the Python standard library. The MQTT tools need paho-mqtt 2.x, and the relay also needs azure-eventhub.
Then ask in plain words, for example: "Here is our device-identity export, plan a move off IoT Hub", or "Rewrite this Event Hubs consumer as an MQTT worker".
Is This the Right Move for You?
An Azure IoT Hub migration makes sense when you want a portable, standards-based MQTT setup: arbitrary topics, retained state, device-to-device messaging and a managed MQTT broker that does not tie your firmware to one cloud SDK. If you are still comparing options, start with Azure IoT Hub alternatives and, for twin-heavy designs, Azure Digital Twins alternatives.
The collection also covers HiveMQ, Mosquitto, EMQX, VerneMQ and AWS IoT Core.
Frequently Asked Questions
Can devices keep using the Azure IoT device SDK after the migration?
Usually not. The Azure device SDKs build IoT Hub's username format, SAS tokens and $iothub topics into the client. On ConnectMQ, devices use a standard MQTT library such as Paho, MQTT.js or esp-mqtt with the new topic scheme. The planner lists this as a firmware work item.
How are device twins migrated?
Desired and reported properties are exported with the Azure CLI, stripped of IoT Hub metadata and published as retained messages on devices/{id}/twin/desired and devices/{id}/twin/reported. Devices then read their desired state on connect and publish their full reported state, retained, whenever it changes.
What happens to backends that read from the Event Hubs-compatible endpoint?
During the parallel run, eventhub_relay.py copies that telemetry to ConnectMQ, so backends can switch to MQTT subscriptions before any device moves. After cutover, the relay and its consumer group are removed and backends read only from ConnectMQ.
Do X.509 certificate devices work with ConnectMQ?
ConnectMQ authenticates with username and password over TLS and does not accept client certificates. X.509 devices need a firmware or configuration change before they can move. The device report counts them so the change can be scheduled early.
Is the Azure IoT Hub migration toolkit free?
Yes. The skills and scripts are MIT licensed on GitHub. Pull requests with new IoT Hub features, backend patterns or script fixes are welcome.



