I'm using azure eventhub in order to stream devices data, and I want to ensure that each device data will go to the same partition. The flow is sending data to iot hub where each device has it's own partition key, and send it to eventhub with same partition key as the iot hub partition key (They have the same amount of partitions). I tried to set eventdata.partitionkey property equals to iothub partition key, but I understand now that this property is hash value and if i'm setting partitionkey = 1 it won't necessarily go to partition 1. And with this solution the eventhub partition distribution is pretty bad (half of the partitions not getting any data at all). I also tried to use CreatePartitionedSender which gives the result, but each time I create partition sender its like creating eventhub client and I get error about the number of connections (Number of AMQP connections per namespace limit).
What will be the better solution:
- Write a factory class (Is there factory already written?) for PartitionSender so I will have 1 client for each partition, and I will have to handle health and maybe some concurrency.
- Working with eventdata.partitionkey property and set a better hash value (maybe the device id instead of partition number) and I wont have to write anything extra or handle connection errors.
Or maybe there is a better solution?
Update: I tried to set eventdata.partitionkey to the device id, but I got error "All event data in a SendBatch operation must have the same partition key". So this is bad solution since if I split each send by the partition key I will have a lot of send operation of small chunks instead of only 1
. Thanks.