How to Route IoT Hub massages to Service Bus Queue in Azure?

Views: 360
Comments: 0
Like/Unlike: 0
Posted On: 25-May-2024 00:26 

Share:   fb twitter linkedin
Pratibha
132 Points
10 Posts


Service Bus queues are commonly used for integrating IoT data with existing backend systems, such as enterprise applications, data warehouses, or real-time analytics pipelines. Also, we can utilize Service Bus Queue Trigger azure function.


[source: Microsoft]

Routing messages from IoT Hub to Service Bus queues facilitates seamless integration with these systems, enabling data-driven decision-making and automation. To route messages from an Azure IoT Hub to an Azure Service Bus queue, you can follow these steps:

  1. Set up your IoT Hub
    Create an IoT Hub in the Azure portal if you haven't already. Register your IoT devices and configure them to send messages to the IoT Hub. Refer here: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal

  2. Set up your Service Bus
    1. Create a Service Bus Namespace in the Azure portal
      Create a Service Bus namespace in the Azure portal if you haven't already:
      1. Navigate to the All services page.
      2. On the left navigation bar, select Integration from the list of categories, hover the mouse over Service Bus, and then select + button on the Service Bus tile.



      3. In the Basics tag of the Create namespace page by following instructions
    2. Create a queue under your Service Bus namespace
      1. On the Service Bus Namespace page, select Queues in the left navigational menu.
      2. On the Queues page, select + Queue on the toolbar.
      3. Enter a name for the queue, and leave the other values with their defaults.
      4. Now, select Create

  3. Create a route in IoT Hub
    IoT Hub currently supports the following endpoints for message routing:
    1. Built-in endpoint
    2. Storage containers
    3. Service Bus queues
    4. Service Bus topics
    5. Event Hubs
    6. Cosmos DB
    In this article we will talk about Service Bus Queue Route. In the Azure portal, navigate to your IoT Hub.
    1. Open your IoT Hub in the Azure portal.
    2. In the left menu, under "Hub Setting", select "Message routing".



    3. Click on "Add" to create a new route.


    4. Configure the route by specifying a name, query condition (optional), and endpoint type (Service Bus Queue).
    5. Choose the Service Bus namespace and queue you created earlier.


    6. Save the route configuration.

  4. Test the message routing
    Send messages from your IoT devices to the IoT Hub. Verify that the messages are being routed to the Service Bus queue by checking the queue in the Azure portal or by consuming messages from the queue programmatically.

  5. Next, Now messages are getting queued in the Service Bus Queue. Here we can create a Service Bus Queue Trigger Azure function. And IoT message will be routed
    1. from IoT devices to IoT Hub
    2. then to Service Bus Queue
    3. then to azure function (service bus trigger function)
    4. then make business logic to store message to the our system/db/platform.

 

0 Comments
 Log In to Chat