Skip to content

Commit 0c2b9a8

Browse files
Merge pull request #219383 from xujing-ms/master
Update how-to-routing-azure-cli.md
2 parents f801a02 + 7482e14 commit 0c2b9a8

File tree

2 files changed

+80
-5
lines changed

2 files changed

+80
-5
lines changed

articles/iot-hub/how-to-routing-azure-cli.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ To learn more about how routing works in IoT Hub, see [Use IoT Hub message routi
1818
## Prerequisites
1919

2020
The procedures that are described in the article use the following resources:
21-
2221
* The Azure CLI
2322
* An IoT hub
2423
* An endpoint service in Azure
@@ -43,6 +42,7 @@ To create an IoT hub route, you need at least one other Azure service to use as
4342

4443
Decide which route type you want to create: an event hub, a Service queue or topic, or a storage account. For the service you choose to use, complete the steps to create an endpoint service.
4544

45+
4646
# [Event Hubs](#tab/eventhubs)
4747

4848
You can choose an Event Hubs resource (namespace and entity).
@@ -185,6 +185,24 @@ You can choose an Azure Storage resource (account and container).
185185

186186
For more information, see [Create a storage account](../storage/common/storage-account-create.md?tabs=azure-cli).
187187

188+
# [Cosmos DB](#tab/cosmosdb)
189+
190+
You can choose a Cosmos DB endpoint.
191+
192+
### Create an Azure Storage resource with container
193+
194+
1. Create a new Cosmos DB account for SQL API
195+
```azurecli
196+
az group create --name my-resource-group --location "eastus"
197+
az cosmosdb create --name my-cosmosdb-account --resource-group my-resource-group
198+
```
199+
2. Create a Cosmos DB container
200+
```azurecli
201+
az cosmosdb sql database create --account-name my-cosmosdb-account --resource-group my-resource-group --name my-cosmosdb-database
202+
az cosmosdb sql container create --account-name my-cosmosdb-account --resource-group my-resource-group --database-name my-cosmosdb-database --name my-cosmosdb-database-container --partition-key-path "/my/path"
203+
```
204+
For more information, see [Create an Azure Cosmos DB for NoSQL](/cosmos-db/scripts/cli/nosql/create).
205+
188206
---
189207

190208
## Create an endpoint
@@ -283,6 +301,32 @@ The commands in the following procedures use these references:
283301

284302
For more parameter options, see [az iot hub routing-endpoint](/cli/azure/iot/hub/routing-endpoint).
285303

304+
# [Cosmos DB](#tab/cosmosdb)
305+
306+
References used in the following commands:
307+
* [az cosmosdb](/cli/azure/cosmosdb)
308+
* [az iot hub](/cli/azure/iot/hub)
309+
310+
### Create a Cosmos DB endpoint
311+
312+
1. Find the Cosmos DB connection string and copy for later use.
313+
314+
```azurecli
315+
az cosmosdb keys list --name my-cosmosdb-account --resource-group my-resource-group --type connection-strings
316+
```
317+
318+
1. Create your custom endpoint. Use the connection string in this command that you copied in the last step. The `endpoint-type` must be `eventhub`, otherwise all other values should be your own.
319+
320+
```azurecli
321+
az iot hub message-endpoint cosmosdb-collection create --resource-group my-resource-group --hub-name my-iot-hub --endpoint-name my-cosmosdb-endpoint --endpoint-account my-cosmosdb-account --database-name my-cosmosdb-database --container my-cosmosdb-database-container --connection-string "copied-connection-string"
322+
```
323+
> [!NOTE]
324+
> If you are using managed identities instead of connection string, you have to use the following command to authenticate your identity to the CosmosDB account.
325+
To see all routing endpoint options, see [az iot hub routing-endpoint](/cli/azure/iot/hub/routing-endpoint).
326+
327+
```azurecli
328+
az cosmosdb sql role assignment create -a my-cosmosdb-account -g my-resource-group --scope '/' -n 'Cosmos DB Built-in Data Contributor' -p "IoT Hub System Assigned or User Assigned Identity"
329+
```
286330
---
287331

288332
## Create an IoT Hub route
@@ -410,7 +454,37 @@ In IoT Hub, you can create a route to send messages or capture events. Each rout
410454
"source": "DeviceConnectionStateEvents"
411455
}
412456
```
457+
# [Cosmos DB](#tab/cosmosdb)
458+
459+
1. With your existing Cosmos DB endpoint, create a new IoT Hub route, using that endpoint. Use the endpoint name for `endpoint`. Use a unique name for `route-name`.
460+
461+
The default fallback route in IoT Hub collects messages from `DeviceMessages`, so let's choose another option for our custom route, such as `DeviceConnectionStateEvents`. For more source options, see [az iot hub route](/cli/azure/iot/hub/route#az-iot-hub-route-create-required-parameters).
462+
463+
```azurecli
464+
az iot hub route create --endpoint my-cosmosdb-endpoint --hub-name my-iot-hub --route-name my-cosmosdb-route --source deviceconnectionstateevents
465+
```
413466

467+
1. A new route should show in your IoT hub. Run this command to confirm the route is there.
468+
469+
```azurecli
470+
az iot hub route list -g my-resource-group --hub-name my-iot-hub
471+
```
472+
473+
You should see a similar response in your console.
474+
475+
```json
476+
[
477+
{
478+
"condition": "true",
479+
"endpointNames": [
480+
"my-cosmosdb-endpoint"
481+
],
482+
"isEnabled": true,
483+
"name": "my-cosmosdb-route",
484+
"source": "DeviceConnectionStateEvents"
485+
}
486+
]
487+
```
414488
---
415489

416490
### Update an IoT Hub route
@@ -452,4 +526,5 @@ az iot hub route delete --resource-group my-resource-group --hub-name my-iot-hub
452526

453527
In this how-to article, you learned how to create a route and endpoint for Event Hubs, Service Bus queues and topics, and Azure Storage.
454528

455-
To learn more about message routing, see [Tutorial: Send device data to Azure Storage by using IoT Hub message routing](./tutorial-routing.md?tabs=cli). In the tutorial, you create a storage route and test it with a device in your IoT hub.
529+
To learn more about message routing, see [Tutorial: Send device data to Azure Storage by using IoT Hub message routing](./tutorial-routing.md?tabs=cli). In the tutorial, you create a storage route and test it with a device in your IoT hub.
530+

articles/iot-hub/iot-hub-device-management-iot-toolkit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.author: junhan
1313

1414
![End-to-end diagram](media/iot-hub-get-started-e2e-diagram/2.png)
1515

16-
In this article, you learn how to use Azure IoT Tools for Visual Studio Code with various management options on your development machine. [Azure IoT Tools](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-tools) is a useful Visual Studio Code extension that makes IoT Hub management and IoT application development easier. It comes with management options that you can use to perform various tasks.
16+
In this article, you learn how to use Azure IoT Tools for Visual Studio Code with various management options on your development machine. [Azure IoT Hub for VS Code](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-toolkit) is a useful Visual Studio Code extension that makes IoT Hub management and IoT application development easier. It comes with management options that you can use to perform various tasks.
1717

1818
[!INCLUDE [iot-hub-basic](../../includes/iot-hub-basic-whole.md)]
1919

@@ -35,7 +35,7 @@ Device twins are JSON documents that store device state information (metadata, c
3535
* An active Azure subscription.
3636
* An Azure IoT hub under your subscription.
3737
* [Visual Studio Code](https://code.visualstudio.com/)
38-
* [Azure IoT Tools for VS Code](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-tools) or copy this URL and paste it into a browser window:`vscode:extension/vsciot-vscode.azure-iot-tools`.
38+
* [Azure IoT Hub for VS Code](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-toolkit) or copy this URL and paste it into a browser window:`vscode:extension/vsciot-vscode.azure-iot-toolkit`.
3939

4040
## Sign in to access your IoT hub
4141

@@ -86,6 +86,6 @@ To send a message from your IoT hub to your device, follow these steps:
8686

8787
## Next steps
8888

89-
You've learned how to use Azure IoT Tools extension for Visual Studio Code with various management options.
89+
You've learned how to use Azure IoT Hub for Visual Studio Code with various management options.
9090

9191
[!INCLUDE [iot-hub-get-started-next-steps](../../includes/iot-hub-get-started-next-steps.md)]

0 commit comments

Comments
 (0)