Welcome to the Microsoft Q&A Platform! Thank you for reaching out regarding your query on Event Grid mqtt topic filtering for Azure functions
Yes, it is possible to implement topic-based filtering within Event Grid to direct messages from specific MQTT topics to their designated functions. You can use the "Advanced Filters" feature in Event Grid to filter events based on the MQTT topic.
Here's how you can set up topic-based filtering in Event Grid:
- Create a new subscription for each function that you want to trigger based on a specific MQTT topic. When creating the subscription, specify the MQTT topic as the "Subject Begins With" filter.
- In your Azure Function code, use the "EventGridTrigger" attribute to specify the subscription name that corresponds to the MQTT topic you want to handle. For example:
public static void Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log) {
// Handle the event based on the MQTT topic
}
In this example, the function will only be triggered for events that match the subscription with the specified name.
- Publish MQTT messages to the appropriate topics. Only the functions that have a subscription with a matching "Subject Begins With" filter will be triggered.
Note that the "Subject Begins With" filter is a prefix match, so you can use wildcards to match multiple topics. For example, if you want to trigger a function for all MQTT topics that start with "Devices/DeviceType1", you can set the "Subject Begins With" filter to "Devices/DeviceType1/*".
I hope this helps! Let me know if you have any further questions.