ParitionKey is null in EventHub Messages when routed from IotHub

Vijay Karthik G 21 Reputation points
2021-11-02T06:28:33.363+00:00

We have set up IoT architecture where we have multiple device sending MQTT messages to Iot Hub. Then the telemetry messages from IoT Hub is routed to a event hub(custom) endpoint. The event hub has four partitions .
We are consuming the messages using default consumer group. The question I have is how the device telemetry will be stored across the partitions ?.If it is based on a hash function on DeviceId , the partition key will be unique for 1000's of devices , so in that case whether a single partition is sufficient or your suggestion would be using multiple partitions(i.e Is there any chance of performance improvement if we use multiple partitions).One more question is we are reading event from Event Hub using Event Processor client , the retrieved events have the PartitionKey Values as null. Is there any specific reason for this null value in retrived events?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,127 questions
Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
560 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 29,196 Reputation points MVP
    2021-11-02T18:33:27.307+00:00

    Hello @Vijay Karthik G ,

    partitionkeys are used to streamline and scale resources like the iothub and eventhub. Once you have chosen a certain number of partitions (4 by default for an IoT Hub) it's normal to use that same number downstream (like in the evenhub). Otherwise, it acts as a funnel, blocking ingestion.

    Normally, 4 partitions should be enough for the majority of customers. See this documentation with background information about choosing the number of partitions.

    Regarding the null values, I did a quick experiment.

    I created an IoT Hub with 4 partitions:

    145866-image.png

    I also created an eventhub with 4 partitions:

    145857-image.png

    A custom endpoint and route is added to send data to the eventhub:

    145867-image.png

    I send messages from a simulated device:

    145865-image.png

    The Eventhub offers a quick insight into the incoming data using the Process data menu:

    145883-image.png

    Explore:

    145891-image.png

    Here you see the partition key in the query editor:

    145816-image.png

    So technically, the partitioning seems to work out well. Please double-check your code.