Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

Deliver IoT Device Telemetry to Other Services Using Event Grid

As an alternative to Azure IoT Hub routing, Event Grid can help us route messages to additional Azure services through topics and subscriptions. In this lab, we will integrate an Azure IoT Hub with Event Grid and set up a subscriber service to consume messages sent by a simulated device. As an extra challenge, the configuration of your Event Grid topic and subscription will be described in an ARM template, which you will use as your roadmap, while navigating through the Event Grid wizard in the Azure portal.

Azure icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 45m
Published
Clock icon Feb 25, 2022

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create and Connect a Simulated Device to Azure IoT Hub

    1. Log in to the Azure portal, and navigate to the only IoT Hub already deployed in the lab subscription.
    2. Create a new device, and copy the Primary Connection String.
    3. Use the following link to open the device simulator in a new browser tab or window.
    4. Once the simulator is open, in the code pane, find and modify the connection string using the Primary Connection String you copied from the new device registration.
    5. Run the code and observe changes in the telemetry messages.
    6. Allow the code to continue to run.
    7. Back in the Azure portal subscription, return to the IoT Hub, and view the IoT Hub Usage tile. You should see at least a few messages after the simulated device has been running a few minutes. Refresh as needed. Note: Even after confirming message delivery in the hub, allow the simulated device to continue sending messages. You will want data to be streaming in order to validate your Event Grid solution in the remaining objectives.
  2. Challenge

    Create an Event Grid Topic and Subscription

    1. Retrieve the ARM template as directed in the Additional Resources section of this lab, and open it in Visual Studio Code or another code editor. A text editor is fine, but it will be harder to read.
    2. In the Azure portal, go to the Azure IoT Hub where your device is deployed. Select Events to add a new Event Grid subscription and topic.
    3. Using the ARM template as your guide, walk through the wizard to create a new topic and subscription that matches, as closely as possible, the resources described in the ARM template. Optional: In the last step of the wizard, on the Advanced tab, the portal displays an ARM template of the resources you are about to create. Copy the template code and save it in a .JSON document for later reference. Tip: See the Additional Resources section of this lab for tips on utilizing the ARM template.
  3. Challenge

    Verify Your Event Grid Integration

    1. Double-check that the simulated device is continuing to send telemetry to the hub.
    2. On the Events page (where you should have landed after creating the topic and subscription), refresh the metrics charts to verify that data is flowing through the Event Grid. You may need to wait a few minutes after deployment for data to begin flowing. Also, because the Event Grid subscription has a filter based on a randomly generated temperature value of above 30 degrees, you may have an additional delay in seeing messages flowing through Event Grid.
    3. Navigate to the target event handler of the subscription endpoint you created, and verify that the correct data is arriving there. **Note: ** The message header will be in clear text, but the message body is encrypted, which is the expected behavior.
    4. Optional: If you chose to save off the ARM template of your new resources in the last objective, use whatever code-compare feature you have in your code editor to see how close your new template came to matching the template you were provided.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans