Azure IoT Hub
Azure IoT Hub provides a local model of the Microsoft.Devices/IotHubs ARM management surface. It lets CLI, SDK, and infrastructure clients create hubs, retain their settings, inspect endpoint metadata, manage consumer groups, and retrieve shared-access keys. It does not yet run the device registry or device message plane. For the wider service map, see Azure platform services. Related ARM views are covered by Azure Resource Graph, Azure Authorization RBAC, Azure Policy Service, and Azure Policy Insights; Azure AI Search and Azure SignalR Service describe other sibling services.
Management surface
The IoT Hub ARM surface manages hubs in resource groups and exposes subscription or resource-group listing. It also provides name checks, read-only hub views, shared-access key actions, and consumer groups for the built-in Event Hub-compatible endpoint.
| Operation | Purpose |
|---|---|
PUT, GET, PATCH, DELETE on .../Microsoft.Devices/IotHubs/{name} | Create, read, update, or remove a hub |
GET on the collection | List hubs in a resource group or subscription |
POST on checkNameAvailability | Check the global hub name before creation |
GET on {name}/skus, {name}/quotaMetrics, or {name}/IotHubStats | Read SKU, quota, or registry summary views |
POST on {name}/listkeys | Return all shared-access policies and keys |
POST on {name}/IotHubKeys/{keyName}/listkeys | Return one named policy and its keys |
GET, PUT, DELETE on {name}/eventHubEndpoints/events/ConsumerGroups/{group} | Read or manage consumer groups on the built-in endpoint |
PUT returns a ready hub with Active state and Succeeded provisioning state. The local service completes the write before it responds, so clients do not need a separate provisioning poll. PATCH changes tags only. A hub read contains the resource and service settings, but not shared-access policies or keys. Clients use the key actions for those. A new hub has the $Default consumer group, which cannot be deleted; other groups remain separate child resources.
The management flow is shown below.
flowchart LR
A[CLI, SDK, or IaC client] --> B[Microsoft.Devices ARM path]
B --> C{Request type}
C --> D[Create or update hub]
C --> E[Read or list hubs and views]
C --> F[Read shared-access keys]
C --> G[Manage consumer groups]
D --> H[Stored local hub]
E --> H
F --> H
G --> H
References: src/…/IotHubArmService.java• L173-239 src/…/IotHubArmService.java• L242-280 src/…/IotHubArmService.java• L489-639 src/…/IotHubCatalog.java• L22-76
Resource identity and naming
An IoT Hub has an ARM resource ID inside a resource group, but its DNS name is global. A hub named my-hub claims my-hub.azure-devices.net in the active cloud profile. A second hub with that name is not available even when it uses another resource group or subscription.
Hub names must be 3 to 50 characters. They can contain letters, digits, and hyphens. They cannot be all digits or start or end with a hyphen. Name availability reports malformed names as invalid and existing global names as already used. A conflicting create returns a conflict instead of creating a second owner.
Consumer group names are separate child-resource names. They allow letters, digits, hyphens, periods, and underscores within 50 characters. $Default is the built-in group and is matched without regard to case.
The location is fixed when the hub is created. A later write that names a different location is rejected. Deleting a hub releases its global name, so a later hub can reuse it.
References: src/…/IotHubArmSurface.java• L20-58 src/…/IotHubArmService.java• L447-464 src/…/IotHubArmService.java• L1210-1218
Persistence and update rules
The hub is local ARM state managed by the IoT Hub storage service. In persistent mode, a restart keeps the hub, its policy keys, its ETag, its creation time, its consumer groups, and the generated names of its built-in endpoint. These values let a client continue to use the same resource after the process starts again.
PUT has replacement semantics for hub settings. Omitted property sections receive Azure-like defaults. A section sent as an empty object or list stays empty. The shared-access policy collection is the exception: an omitted or null collection keeps the current policies and keys. A PUT also keeps the built-in endpoint names, creation time, and consumer groups while the hub exists.
The service changes the ETag on every successful hub write. A caller can omit If-Match or use *; a specific value must match the current ETag. A stale value returns 412 PreconditionFailed. An ETag from a deleted hub cannot update a new hub created under the same ID. Consumer-group changes do not change the hub ETag because groups are child resources.
The service stores the event endpoint partition count at creation. A later update can leave it out and keep it, but cannot change it. The local admin reset clears all hubs and releases their names.
References: src/…/IotHubModels.java• L64-142 src/…/IotHubArmService.java• L304-394 src/…/IotHubArmService.java• L526-609 src/…/IotHubArmService.java• L856-895 src/…/IotHubArmService.java• L1182-1208
Endpoint routing
The ARM response describes the endpoints that Azure IoT Hub would use, but the local service does not serve those device or message routes. hostName is derived from the hub name and the cloud IoT Hub suffix. The built-in events endpoint has generated partition IDs, an Event Hub path, and a Service Bus endpoint whose names remain stable for the hub's lifetime.
The routing property is configuration state only. The service keeps custom endpoints, routes, enrichments, and the fallback route in the ARM resource, but it does not deliver telemetry or check that the referenced destinations exist. The hostName, Event Hub endpoint, and connection strings therefore describe setup state rather than usable local data-plane addresses.
Consumer groups are managed only on the built-in events endpoint. The service lists $Default first and then other groups in creation order. It accepts the path spellings used by common clients, but it does not turn the endpoint into a local telemetry stream.
The endpoint boundary is shown below.
flowchart LR
A[ARM hub request] --> B[Local hub state]
B --> C[Derived host name]
B --> D[Event Hub-compatible endpoint metadata]
B --> E[Stored routing configuration]
B --> F[Consumer group metadata]
C --> G[Read by management clients]
D --> G
E --> G
F --> G
G -. device or telemetry traffic .-> H[Not served locally]
References: src/…/IotHubArmService.java• L491-645 src/…/IotHubArmService.java• L680-739 src/…/IotHubArmService.java• L741-821 src/…/IotHubModels.java• L21-24
Shared-access credentials
Each new hub starts with five Azure default shared-access policies: iothubowner, service, device, registryRead, and registryReadWrite. Each policy has a primary key, a secondary key, and a rights set. Custom policies can be added or removed by sending the complete authorizationPolicies collection in a PUT.
Policy updates follow these rules:
- An omitted or
nullpolicy collection keeps the existing policies and keys. - A supplied collection replaces the policy set. A policy that is missing from the request is removed.
- A supplied key is kept. A missing primary or secondary key is generated again.
- A policy without a key is therefore the mechanism used to renew that key.
listkeysreturns the keys. A normal hubGETdoes not expose them.
The hub also holds secrets for configured storage and routing endpoints. Reads mask secret parts of connection strings and mask Cosmos DB primary and secondary keys. When a client sends that masked response back, the service restores the stored secret only when it finds the same endpoint. A renamed endpoint or a mask with no stored value is rejected instead of saving **** as a real secret.
References: src/…/IotHubArmService.java• L99-105 src/…/IotHubArmService.java• L334-370 src/…/IotHubArmService.java• L468-487 src/…/IotHubArmService.java• L898-983 src/…/Secrets.java• L12-19 src/…/Secrets.java• L34-76
Change checklist
When these files or sections are changed, remember to consider these:
- If the ARM resource path or action set changes, keep resource-group writes, subscription listing, name availability, views, consumer groups, and both key actions aligned.
- If name validation or cloud suffix handling changes, update global-name ownership, conflict checks,
hostName, and the related endpoint suffix together. - If
PUTdefaults or replacement rules change, preserve the distinction between omitted sections, explicit empty sections, and the policy collection. - If persistent fields change, keep policy keys, ETags, creation identity, generated endpoint names, and consumer groups recoverable across restart and distinct after delete-and-recreate.
- If secret masking changes, keep read responses, masked write-back, endpoint-name matching, and unresolvable-mask errors consistent.
- If endpoint routing fields change, keep the ARM representation clear that routing is stored configuration and not local message delivery.
- If consumer-group behavior changes, keep
$Defaultcreation and protection, endpoint validation, case-insensitive lookup, and hub ETag rules aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A hub name is already owned in another resource group or subscription | Create fails with a global name conflict | Check availability and treat the name as a cloud-wide DNS label |
| A write uses an old specific ETag | The write returns 412 PreconditionFailed and does not change the hub | Re-read the hub before retrying, or use an intentional wildcard write |
A PUT omits a settings section that the client expected to retain | That section returns to its Azure-like default | Send the full section when its current values matter |
A PUT changes the existing event endpoint partition count | The update is rejected | Set the partition count only when the hub is first created |
| A client sends a masked secret for a new or renamed endpoint | The request returns 400 InvalidRequestContent | Preserve the endpoint name or send the real secret |
A client uses hostName, routing settings, or the Event Hub endpoint for device traffic | The local emulator does not serve the device or message request | Use the IoT Hub page for ARM setup only until the data plane is supported |
| A process restarts while IoT Hub storage is not persistent | Local hubs and their generated credentials are not available after restart | Enable the IoT Hub persistent storage mode for restart-based workflows |
A client targets an endpoint other than events or deletes $Default | The consumer-group request fails | Use the built-in events endpoint and keep $Default |
Key files
| File | Why to read it |
|---|---|
| src/…/IotHubArmSurface.java | Defines the provider surface, resource-group scope, name rules, child resources, and global name claim |
| src/…/IotHubArmService.java | Shows the hub lifecycle, ARM actions, defaults, ETags, endpoint metadata, consumer groups, and policy actions |
| src/…/IotHubCatalog.java | Defines the read-only operation catalog and quota views exposed by the ARM surface |
| src/…/IotHubModels.java | Shows which hub identity, generated values, policies, and consumer groups must persist |
| src/…/Secrets.java | Shows masking and restoration rules for endpoint credentials |
| src/…/IotHubArmServiceTest.java | Captures the ARM response shape, defaults, update behavior, and key contract |
| src/…/IotHubPersistenceTest.java | Shows the values required to survive a persistent-storage restart |
| src/…/SecretsTest.java | Shows secret masking, endpoint-name matching, and unresolved-mask rejection |
| src/…/application.yml | Shows the IoT Hub service enablement and service-level configuration entry |