Connect Azure Iot Hub message route with Azure function Event Hub

Question:

Is it possible to connect a message route set as event to an azure function. I have only managed to connect to event hub compatible endpoint but not with a specific message route

I have set "EventHubName": "messages/events/valid-route" in function.json

Asked By: Oswaldo Hernandez

||

Answers:

Is it possible to connect a message route set as event to an azure
function. I have only managed to connect to event hub compatible
endpoint but not with a specific message route

I have set "EventHubName": "messages/events/valid-route" in
function.json

You need to add more details on your specific scenario for better understanding so others can check and provide helpful suggestions.

What happens after you test the routing by adding "messages/events/valid-route" in function.json ? Are you seeing any error messages?

Based on the above query, You would like to connect a message route set as event to an Azure Function which is not available in a built-in-endpoint currently.

Note that 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.

IoT Hub currently supports the following Azure services as custom endpoints:

  • Storage containers
  • Event Hubs
  • Service Bus Queues
  • Service Bus Topics
  • Cosmos DB (preview)

For more information about message routing, see Use IoT Hub message routing to send device-to-cloud messages to different endpoints.

To use Azure Functions with IoT Hub message routing, I would suggest you check out the blog post on Use Azure Functions with IoT Hub message routing for more details.

Feel free to comment if you have any further queries.

Answered By: AshokPeddakotla

Function.json should look like this for getting messages from a route. You have to define the route in the path setting

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "events",
      "direction": "in",
      "eventHubName": "%EventHubName%",
      "connection": "IoTHubTriggerConnection",
      "cardinality": "many",
      "consumerGroup": "$Default",
      "path": "valid-route"
    }
  ]
}
Answered By: Oswaldo Hernandez