Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 4a7634e

Browse files
authored
Update readme to use the latest Event Hubs SDK (#23)
1 parent 379769d commit 4a7634e

File tree

1 file changed

+38
-8
lines changed
  • iot-hub/Quickstarts/read-d2c-messages

1 file changed

+38
-8
lines changed

iot-hub/Quickstarts/read-d2c-messages/Readme.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
# Read device to cloud messages (Python)
22

3-
Currently there is no pip available for the Azure Event Hubs client.
3+
Use the Microsoft Azure Event Hubs Client for Python to read messages sent from a device by using the
4+
built-in event hubs that exists by default for every Iot Hub instance. For more details, see the
5+
documentation for the [azure-eventhub](https://pypi.org/project/azure-eventhub/) package.
46

5-
The options are:
7+
## Get Event Hubs-compatible connection string
8+
9+
You can get the Event Hubs-compatible connection string to your IotHub instance via the Azure portal or
10+
by using the Azure CLI.
11+
12+
If using the Azure portal, see [Built in endpoints for IotHub](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-messages-read-builtin#read-from-the-built-in-endpoint) to get the Event Hubs-compatible
13+
connection string.
14+
15+
If using the Azure CLI, you will need to run the below to get the Event Hubs-compatible endpoint, path
16+
and the SAS key for the "service" policy.
17+
18+
- `az iot hub show --query properties.eventHubEndpoints.events.endpoint --name {your IoT Hub name}`
19+
- `az iot hub show --query properties.eventHubEndpoints.events.path --name {your IoT Hub name}`
20+
- `az iot hub policy show --name service --query primaryKey --hub-name {your IoT Hub name}`
21+
22+
Then, form the Event Hubs-compatible connection string as below
23+
`Endpoint=eventHubsCompatibleEndpoint/;EntityPath=eventHubsCompatiblePath;SharedAccessKeyName=service;SharedAccessKey=iotHubSasKey`.
24+
25+
With the Event Hubs-compatible connection string now in hand, you can now use the EventHubConsumerClient from the
26+
[azure-eventhub](https://pypi.org/project/azure-eventhub/) package as shown in any of the receive related samples below
27+
- [sync samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/sync_samples)
28+
- [async samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/eventhub/azure-eventhub/samples/async_samples)
29+
30+
If you cannot get the Event Hubs-compatible connection string in the above manner, and need to programatically get this information,
31+
then use the [sample to convert IotHub connection string to an Event Hubs-compatible one](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventhub/azure-eventhub/samples/async_samples/iot_hub_connection_string_receive_async.py). This conversion is done by connecting to
32+
the IoT hub endpoint and receiving a redirection address to the built-in event hubs. This address is then used
33+
in the Event Hubs Client to read messages.
34+
35+
## Checkpointing
36+
37+
For an example that uses checkpointing, use the checkpoint store from
38+
- [azure-eventhub-checkpointstoreblob](https://pypi.org/project/azure-eventhub-checkpointstoreblob/) package for sync
39+
- [azure-eventhub-checkpointstoreblob-aio](https://pypi.org/project/azure-eventhub-checkpointstoreblob-aio/) package for async
40+
41+
The above links have documentation on samples on how to use the checkpoint store.
642

7-
* Build a docker image.
8-
* Build the libraries manually.
943

10-
For more information, see https://github.com/Azure/azure-event-hubs-python
1144

12-
To keep this quickstart simple, you are using the iothub-explorer CLI tool to monitor telemetry sent to the hub:
1345

14-
npm install -g iothub-explorer
15-
iothub-explorer monitor-events MyPythonDevice --login {your hub service connection string}

0 commit comments

Comments
 (0)