Skip to content

Commit a8efabe

Browse files
authored
Merge pull request #267129 from kgremban/feb23-hubfreshness
IoT Hub freshness - routing and endpoints
2 parents ccfb43d + e5019d3 commit a8efabe

13 files changed

+150
-145
lines changed

articles/iot-hub/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
- name: Schedule jobs on multiple devices
7979
href: iot-hub-devguide-jobs.md
8080
- name: IoT Hub endpoints
81-
displayName: multi-tenant
81+
displayName: multitenant
8282
href: iot-hub-devguide-endpoints.md
8383
- name: Queries
8484
items:
@@ -131,7 +131,7 @@
131131
href: iot-hub-message-enrichments-overview.md
132132
- name: Message routing
133133
items:
134-
- name: Use message routing to send device-to-cloud messages
134+
- name: Route device-to-cloud messages to Azure services
135135
displayName: endpoints, built-in endpoint, Azure storage, Service Bus Queues, fallback, route
136136
href: iot-hub-devguide-messages-d2c.md
137137
- name: Add queries to message routes

articles/iot-hub/authenticate-authorize-azure-ad.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The following table describes the permissions available for IoT Hub service API
9292
> - Both [Invoke Component Command](/rest/api/iothub/service/digitaltwin/invokecomponentcommand) and [Invoke Root Level Command](/rest/api/iothub/service/digitaltwin/invokerootlevelcommand) require `Microsoft.Devices/IotHubs/directMethods/invoke/action`.
9393
9494
> [!NOTE]
95-
> To get data from IoT Hub by using Microsoft Entra ID, [set up routing to a separate event hub](iot-hub-devguide-messages-d2c.md#event-hubs-as-a-routing-endpoint). To access the [the built-in Event Hubs compatible endpoint](iot-hub-devguide-messages-read-builtin.md), use the connection string (shared access key) method as before.
95+
> To get data from IoT Hub by using Microsoft Entra ID, [set up routing to a custom Event Hubs endpoint](iot-hub-devguide-messages-d2c.md). To access the [the built-in Event Hubs compatible endpoint](iot-hub-devguide-messages-read-builtin.md), use the connection string (shared access key) method as before.
9696
9797
<a name='enforce-azure-ad-authentication'></a>
9898

articles/iot-hub/iot-hub-devguide-endpoints.md

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,67 @@ author: kgremban
66
ms.author: kgremban
77
ms.service: iot-hub
88
ms.topic: concept-article
9-
ms.date: 12/21/2022
9+
ms.date: 02/23/2024
1010
ms.custom: [amqp, mqtt, 'Role: Cloud Development', 'Role: System Architecture']
1111
---
1212

1313
# IoT Hub endpoints
1414

15+
Azure IoT Hub exposes various endpoints to support the devices and services that interact with it.
16+
1517
[!INCLUDE [iot-hub-basic](../../includes/iot-hub-basic-partial.md)]
1618

1719
## IoT Hub names
1820

19-
You can find the hostname of the IoT hub that hosts your endpoints in the Azure portal, on your IoT hub's **Overview** working pane. By default, the DNS name of an IoT hub looks like the following example:
21+
You can find the hostname of an IoT hub in the Azure portal, on your IoT hub's **Overview** working pane. By default, the DNS name of an IoT hub looks like the following example:
2022

2123
`{your iot hub name}.azure-devices.net`
2224

23-
## List of built-in IoT Hub endpoints
25+
## IoT Hub endpoints for development and management
2426

25-
Azure IoT Hub is a multi-tenant service that exposes its functionality to various actors. The following diagram shows the various endpoints that IoT Hub exposes.
27+
Azure IoT Hub is a multitenant service that exposes its functionality to various actors. The following diagram shows the various endpoints that IoT Hub exposes.
2628

2729
:::image type="content" source="./media/iot-hub-devguide-endpoints/endpoints.png" alt-text="Diagram showing the list of build-in IoT Hub endpoints." border="false":::
2830

2931
The following list describes the endpoints:
3032

31-
* **Resource provider**. The IoT Hub resource provider exposes an [Azure Resource Manager](../azure-resource-manager/management/overview.md) interface. This interface enables Azure subscription owners to create and delete IoT hubs, and to update IoT hub properties. IoT Hub properties govern [hub-level shared access policies](iot-hub-dev-guide-sas.md#access-control-and-permissions), as opposed to device-level access control, and functional options for cloud-to-device and device-to-cloud messaging. The IoT Hub resource provider also enables you to [export device identities](iot-hub-devguide-identity-registry.md#import-and-export-device-identities).
32-
33-
* **Device identity management**. Each IoT hub exposes a set of HTTPS REST endpoints to manage device identities (create, retrieve, update, and delete). [Device identities](iot-hub-devguide-identity-registry.md) are used for device authentication and access control.
33+
* **Resource provider**: an [Azure Resource Manager](../azure-resource-manager/management/overview.md) interface. This interface enables Azure subscription owners to create and delete IoT hubs, and to update IoT hub properties. IoT Hub properties govern [hub-level shared access policies](./authenticate-authorize-sas.md#access-control-and-permissions), as opposed to device-level access control, and functional options for cloud-to-device and device-to-cloud messaging. The IoT Hub resource provider also enables you to [export device identities](./iot-hub-devguide-identity-registry.md#import-and-export-device-identities).
3434

35-
* **Device twin management**. Each IoT hub exposes a set of service-facing HTTPS REST endpoint to query and update [device twins](iot-hub-devguide-device-twins.md) (update tags and properties).
35+
* **Device identity management**: a set of HTTPS REST endpoints to manage device identities (create, retrieve, update, and delete). [Device identities](iot-hub-devguide-identity-registry.md) are used for device authentication and access control.
3636

37-
* **Jobs management**. Each IoT hub exposes a set of service-facing HTTPS REST endpoint to query and manage [jobs](iot-hub-devguide-jobs.md).
37+
* **Device twin management**: a set of service-facing HTTPS REST endpoint to query and update [device twins](iot-hub-devguide-device-twins.md) (update tags and properties).
3838

39-
* **Device endpoints**. For each device in the identity registry, IoT Hub exposes a set of endpoints. Except where noted, these endpoints are exposed using [MQTT v3.1.1](https://mqtt.org/), HTTPS 1.1, and [AMQP 1.0](https://www.amqp.org/) protocols. AMQP and MQTT are also available over [WebSockets](https://tools.ietf.org/html/rfc6455) on port 443.
39+
* **Jobs management**: a set of service-facing HTTPS REST endpoint to query and manage [jobs](iot-hub-devguide-jobs.md).
4040

41-
* *Send device-to-cloud messages*. A device uses this endpoint to [send device-to-cloud messages](iot-hub-devguide-messages-d2c.md).
41+
* **Device endpoints**: a set of endpoints for each device in the identity registry. Except where noted, these endpoints are exposed using [MQTT v3.1.1](https://mqtt.org/), HTTPS 1.1, and [AMQP 1.0](https://www.amqp.org/) protocols. AMQP and MQTT are also available over [WebSockets](https://tools.ietf.org/html/rfc6455) on port 443. These device endpoints include:
4242

43-
* *Receive cloud-to-device messages*. A device uses this endpoint to receive targeted [cloud-to-device messages](iot-hub-devguide-messages-c2d.md).
43+
* Send device-to-cloud messages
4444

45-
* *Initiate file uploads*. A device uses this endpoint to receive an Azure Storage SAS URI from IoT Hub to [upload a file](iot-hub-devguide-file-upload.md).
45+
* Receive cloud-to-device messages
4646

47-
* *Retrieve and update device twin properties*. A device uses this endpoint to access its [device twin](iot-hub-devguide-device-twins.md)'s properties. HTTPS isn't supported.
47+
* Initiate file uploads
4848

49-
* *Receive direct method requests*. A device uses this endpoint to listen for [direct method](iot-hub-devguide-direct-methods.md) requests. HTTPS isn't supported.
49+
* Retrieve and update device twin properties (HTTPS isn't supported)
5050

51-
[!INCLUDE [iot-hub-include-x509-ca-signed-support-note](../../includes/iot-hub-include-x509-ca-signed-support-note.md)]
51+
* Receive direct method requests (HTTPS isn't supported)
5252

53-
* **Service endpoints**. Each IoT hub exposes a set of endpoints for your solution back end to communicate with your devices. With one exception, these endpoints are only exposed using the [AMQP](https://www.amqp.org/) and AMQP over WebSockets protocols. The direct method invocation endpoint is exposed over the HTTPS protocol.
53+
* **Service endpoints**: a set of endpoints for your solution back end to communicate with your devices. With one exception, these endpoints are only exposed using the [AMQP](https://www.amqp.org/) and AMQP over WebSockets protocols. The direct method invocation endpoint is exposed over the HTTPS protocol.
5454

55-
* *Receive device-to-cloud messages*. This endpoint is compatible with [Azure Event Hubs](../event-hubs/index.yml). A back-end service can use it to read the [device-to-cloud messages](iot-hub-devguide-messages-d2c.md) sent by your devices. You can create custom endpoints on your IoT hub in addition to this built-in endpoint.
55+
* Receive device-to-cloud messages: This endpoint is the built-in endpoint discussed in message routing concepts. A back-end service can use it to read the device-to-cloud messages sent by your devices. You can create custom endpoints on your IoT hub in addition to this built-in endpoint.
5656

57-
* *Send cloud-to-device messages and receive delivery acknowledgments*. These endpoints enable your solution back end to send reliable [cloud-to-device messages](iot-hub-devguide-messages-c2d.md), and to receive the corresponding delivery or expiration acknowledgments.
58-
59-
* *Receive file notifications*. This messaging endpoint allows you to receive notifications of when your devices successfully upload a file.
57+
* Send cloud-to-device messages and receive delivery acknowledgments
58+
59+
* Receive file upload notifications
6060

61-
* *Direct method invocation*. This endpoint allows a back-end service to invoke a [direct method](iot-hub-devguide-direct-methods.md) on a device.
61+
* Invoke direct method
6262

6363
The [Azure IoT Hub SDKs](iot-hub-devguide-sdks.md) article describes the various ways to access these endpoints.
6464

6565
All IoT Hub endpoints use the [TLS](https://tools.ietf.org/html/rfc5246) protocol, and no endpoint is ever exposed on unencrypted/unsecured channels.
6666

67-
## Custom endpoints
67+
[!INCLUDE [iot-hub-include-x509-ca-signed-support-note](../../includes/iot-hub-include-x509-ca-signed-support-note.md)]
68+
69+
## Custom endpoints for message routing
6870

6971
You can link existing Azure services in your Azure subscriptions to your IoT hub to act as endpoints for message routing. These endpoints act as service endpoints and are used as sinks for message routes. Devices can't write directly to these endpoints. For more information about message routing, see [Use IoT Hub message routing to send device-to-cloud messages to different endpoints](../iot-hub/iot-hub-devguide-messages-d2c.md).
7072

@@ -76,21 +78,72 @@ IoT Hub currently supports the following Azure services as custom endpoints:
7678
* Service Bus Topics
7779
* Cosmos DB (preview)
7880

79-
For the limits on the number of endpoints you can add, see [Quotas and throttling](iot-hub-devguide-quotas-throttling.md).
81+
For the limits on endpoints per hub, see [Quotas and throttling](iot-hub-devguide-quotas-throttling.md).
8082

81-
## Endpoint Health
83+
### Built-in endpoint
8284

83-
[!INCLUDE [iot-hub-endpoint-health](../../includes/iot-hub-include-endpoint-health.md)]
85+
You can use standard [Event Hubs integration and SDKs](iot-hub-devguide-messages-read-builtin.md) to receive device-to-cloud messages from the built-in endpoint (**messages/events**). Once any route is created, data stops flowing to the built-in endpoint unless a route is created to that endpoint. Even if no routes are created, a fallback route must be enabled to route messages to the built-in endpoint. The fallback is enabled by default if you create your hub using the portal or the CLI.
86+
87+
### Azure Storage as a routing endpoint
88+
89+
There are two storage services IoT Hub can route messages to: [Azure Blob Storage](../storage/blobs/storage-blobs-introduction.md) and [Azure Data Lake Storage Gen2](../storage/blobs/data-lake-storage-introduction.md) (ADLS Gen2) accounts. Both of these use blobs for their storage.
90+
91+
IoT Hub supports writing data to Azure Storage in the [Apache Avro](https://avro.apache.org/) format and the JSON format. The default is AVRO. To use JSON encoding set the contentType property to **application/json** and contentEncoding property to **UTF-8** in the message [system properties](iot-hub-devguide-routing-query-syntax.md#system-properties). Both of these values are case-insensitive. If the content encoding isn't set, then IoT Hub writes the messages in base 64 encoded format.
92+
93+
The encoding format can be set only when the blob storage endpoint is configured; it can't be edited for an existing endpoint.
94+
95+
IoT Hub batches messages and writes data to storage whenever the batch reaches a certain size or a certain amount of time has elapsed. IoT Hub defaults to the following file naming convention: `{iothub}/{partition}/{YYYY}/{MM}/{DD}/{HH}/{mm}`.
96+
97+
You may use any file naming convention, but you must use all listed tokens. IoT Hub writes to an empty blob if there's no data to write.
98+
99+
We recommend listing the blobs or files and then iterating over them, to ensure that all blobs or files are read without making any assumptions of partition. The partition range could potentially change during a Microsoft-initiated failover or IoT Hub manual failover. You can use the [List Blobs API](/rest/api/storageservices/list-blobs) to enumerate the list of blobs or [List ADLS Gen2 API](/rest/api/storageservices/datalakestoragegen2/path) for the list of files. For example:
84100

85-
## Field gateways
101+
```csharp
102+
public void ListBlobsInContainer(string containerName, string iothub)
103+
{
104+
var storageAccount = CloudStorageAccount.Parse(this.blobConnectionString);
105+
var cloudBlobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference(containerName);
106+
if (cloudBlobContainer.Exists())
107+
{
108+
var results = cloudBlobContainer.ListBlobs(prefix: $"{iothub}/");
109+
foreach (IListBlobItem item in results)
110+
{
111+
Console.WriteLine(item.Uri);
112+
}
113+
}
114+
}
115+
```
86116

87-
In an IoT solution, a *field gateway* sits between your devices and your IoT Hub endpoints. It's typically located close to your devices. Your devices communicate directly with the field gateway by using a protocol supported by the devices. The field gateway connects to an IoT Hub endpoint using a protocol that is supported by IoT Hub. A field gateway might be a dedicated hardware device or a low-power computer running custom gateway software.
117+
To create an Azure Data Lake Gen2-compatible storage account, create a new V2 storage account and select **Enable hierarchical namespace** from the **Data Lake Storage Gen2** section of the **Advanced** tab, as shown in the following image:
88118

89-
You can use [Azure IoT Edge](../iot-edge/index.yml) to implement a field gateway. IoT Edge offers functionality such as multiplexing communications from multiple devices onto the same IoT Hub connection.
119+
:::image type="content" alt-text="Screenshot that shows how to select Azure Date Lake Gen2 storage." source="./media/iot-hub-devguide-messages-d2c/selectadls2storage.png":::
120+
121+
### Service Bus queues and Service Bus topics as a routing endpoint
122+
123+
Service Bus queues and topics used as IoT Hub endpoints must not have **Sessions** or **Duplicate Detection** enabled. If either of those options are enabled, the endpoint appears as **Unreachable** in the Azure portal.
124+
125+
### Event Hubs as a routing endpoint
126+
127+
Apart from the built-in-Event Hubs compatible endpoint, you can also route data to custom endpoints of type Event Hubs.
128+
129+
### Azure Cosmos DB as a routing endpoint (preview)
130+
131+
You can send data directly to Azure Cosmos DB from IoT Hub. IoT Hub supports writing to Cosmos DB in JSON (if specified in the message content-type) or as base 64 encoded binary.
132+
133+
To support high-scale scenarios, you can enable [synthetic partition keys](../cosmos-db/nosql/synthetic-partition-keys.md) for the Cosmos DB endpoint. As Cosmos DB is a hyperscale data store, all data/documents written to it must contain a field that represents a logical partition. Each logical partition has a maximum size of 20 GB. You can specify the partition key property name in **Partition key name**. The partition key property name is defined at the container level and can't be changed once it has been set.
134+
135+
You can configure the synthetic partition key value by specifying a template in **Partition key template** based on your estimated data volume. For example, in manufacturing scenarios, your logical partition might be expected to approach its maximum limit of 20 GB within a month. In that case, you can define a synthetic partition key as a combination of the device ID and the month. The generated partition key value is automatically added to the partition key property for each new Cosmos DB record, ensuring logical partitions are created each month for each device.
136+
137+
> [!CAUTION]
138+
> If you're using the system assigned managed identity for authenticating to Cosmos DB, you must use Azure CLI or Azure PowerShell to assign the Cosmos DB Built-in Data Contributor built-in role definition to the identity. Role assignment for Cosmos DB isn't currently supported from the Azure portal. For more information about the various roles, see [Configure role-based access for Azure Cosmos DB](../cosmos-db/how-to-setup-rbac.md). To understand assigning roles via CLI, see [Manage Azure Cosmos DB SQL role resources.](/cli/azure/cosmosdb/sql/role)
139+
140+
## Endpoint Health
141+
142+
[!INCLUDE [iot-hub-endpoint-health](../../includes/iot-hub-include-endpoint-health.md)]
90143

91144
## Next steps
92145

93-
Other reference topics in this IoT Hub developer guide include:
146+
Learn more about these topics:
94147

95148
* [IoT Hub query language for device and module twins, jobs, and message routing](iot-hub-devguide-query-language.md)
96149
* [IoT Hub quotas and throttling](iot-hub-devguide-quotas-throttling.md)

0 commit comments

Comments
 (0)