2
votes

I'm consuming EventData events from an Azure Event Hub using Azure Functions 1.x. However, I noticed that the PartitionKey is always null. Yet, Offset and SequenceNumber are both populated.

I know it's optional for the sender to set the PartitionKey. In fact, it's recommended not to set it for performance reasons. However, I assumed that somewhere along the way to the consumer, the PartitionKey would be set with the partition that processed the EventData.

If that's not the case, what's the point of sending the Offset and SequenceNumber? Each partition maintains its own Offset and SequenceNumber. If I wanted to replay an event, how would I do so without knowing the PartitionKey?

Edit:

I just found out that if I bind to the PartitionContext, I can view the PartitionId that the EventData came from. Why isn't this used to populate the PartitionKey on the EventData? Is this a bug with Azure Functions?

2

2 Answers

1
votes

The PartitionKey is different from the PartitionId:

PartitionId is different than PartitionKey. Partition keys are used to ensure same partition keys to land on the same partition ids. You can think PartitionKey to partitionId relation as "f(partitionKey) = partitionId" where f is a hashing function.

The PartitionKey will be null if the sender didn't set it, as mentioned by Ling Toh.

You can access the PartitionId in Azure Functions by using the PartitionContext binding.

0
votes

You should be able to obtain the partitionKey property from the EventData object. Kindly see, https://medium.com/@jeffhollan/in-order-event-processing-with-azure-functions-bb661eb55428