I saw at Microsoft Docs that there is a way to send data to the partition I want by setting the PartitionId instead of the PartitionKey (using C#).
CreatePartitionSender(String) Create a PartitionSender which can publish EventData's directly to a specific EventHub partition.
However, I couldn't find the same in Python.
Is any available way?
There are two ways to send data to Azure Event Hubs, which are HTTP REST API and AMQP 1.0 protocol.
For using HTTP REST API or Azure EventHub Python Client Library, only partitionId
parameter supports to send a new event to a specified partition in an Event Hub, as the two below.
The REST API Send partition event
requires the partitionId
parameter in the endpoint https://{servicebusNamespace}.servicebus.windows.net/{eventHubPath}/partitions/{partitionId}/messages
, and it's the only one REST API to support the feature of send partition。
The source code comment of Sender.py
explains the partition
parameter as below.
:param partition: The specific partition ID to send to. Default is None, in which case the service
will assign to all partitions using round-robin.
:type partition: str
So actually, you can not use partitionKey
value to send an event to a specified EventHub partition, except using AMQP 1.0 in Python. For using AMQP 1.0, please see the offical document AMQP 1.0 in Azure Service Bus and Event Hubs protocol guide
and search for the words partition-key
on the page, the result as below.