Event Grid Namespace with MQTT Enabled: Event Subscription processes event where data key is null

Hoß, Jonathan 20 Reputation points
2023-11-13T09:45:12.57+00:00

We have created an Event Grid Namespace with the MQTT feature enabled.

From there we already route the data to an Event-Hubs (as in this tutorial) which triggers an Azure Function. This way works as expected.

Now we want to directly trigger an Azure Function directly from the Event Grid for specific Mqtt topics. Therefore we created a new Event Subscription inside the Event Grid Topic with a prefix filter that matches our Mqtt topic. The filtering works. We are receiving messages, using the Python Azure functions library.

Problem: Data field of event messages is null.

Expected behaviour: The data field of the event message has the value of the json payload of the mqtt message.

We are able to receive messages with the python libary when we send Mqtt Events but the 'data' field is null also the event_type is null.

Here is an example payload we receive in the Azure fuction: tested with azure-functions 1.17.0 https://pypi.org/project/azure-functions/ and azure-functions 1.18.0b3 https://pypi.org/project/azure-functions/1.18.0b3/

def main(event: func.EventGridEvent, signalRMessages: func.Out[str]) -> None:
    event_dict = {
        'id': event.id,
        'data': event.get_json(),
        'topic': event.topic,
        'subject': event.subject,
        'event_type': event.event_type,
    }
{"id": "1572f624-9581-4210-8bf4-6e121c6bd649", "data": null, "topic": null, "subject": "dockerhost02/Kathrein-RTLS/test1", "event_type": null}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,679 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
354 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde | MVP 31,211 Reputation points MVP
    2023-11-13T11:16:44.78+00:00

    Hello Jonathan,

    welcome to this moderated Azure community forum.

    The Data field is only filled when the message is marked as being JSON / UTF-8.

    For MQTT v5 messages of content type= “application/json; charset=utf-8” or of a payload format indicator=1, the payload will be forwarded in the data object, and the message will be serialized as a JSON

    Can you check if the "data_base64" field is filled?

    If so, this field has the same value but encoded as Bas64. You just need to decode it.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


0 additional answers

Sort by: Most helpful