0
votes

I have two devices registered in IoT Hub. say device1 and device2. I have two azure functions say azurefunction1 and azurefunction2.

When a message is sent to Iot Hub with device1 I want azurefunction1 to get triggered but not azurefunction2. Similarly When a message is sent to Iot Hub with device2 I want azurefunction2 to get triggered but not azurefunction1.

I tried using consumer groups but both azure functions are getting triggered. Any help appreciated.

2

2 Answers

0
votes

This is not directly possible. Events from both devices go to the same Event Hub, and Event Hub is the level of granularity for Functions trigger.

Consumer groups are for independent consumers, which both will get all events.

I would suggest you having a single Function to receive events from all devices. This Function could then route the request based on Device ID to other Functions if needed, e.g. via HTTP calls or via separate Storage Queues.

0
votes

Another option is to use IoT Hub routing. You can route events to different IoT Hub endpoints based in the deviceid. You can then have azurefunction1 connected to the endpoint for device1, and azurefunction2 connected to the endpoint for device2.

The Routing Messages tutorial describes how to configure and use routing.