<p>有两种方法可以将数据发送到Azure事件中心,即httprestapi和amqp1.0协议。在</p>
<p>对于使用httprestapi或<a href="https://github.com/Azure/azure-event-hubs-python" rel="nofollow noreferrer">Azure EventHub Python Client Library</a>,只有<code>partitionId</code>参数支持将新事件发送到事件集线器中的指定分区,如下所示。在</p>
<ol>
<li><p>restapi<a href="https://docs.microsoft.com/en-us/rest/api/eventhub/send-partition-event" rel="nofollow noreferrer">^{<cd2>}</a>需要端点<code>https://{servicebusNamespace}.servicebus.windows.net/{eventHubPath}/partitions/{partitionId}/messages</code>中的<code>partitionId</code>参数,它是唯一一个支持发送分区功能的REST API。</p></li>
<li><p><code>Sender.py</code>的源代码注释解释了<a href="https://github.com/Azure/azure-event-hubs-python/blob/master/azure/eventhub/sender.py#L32" rel="nofollow noreferrer">^{<cd6>}</a>参数,如下所示。在</p>
<pre><code>: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
</code></pre></li>
</ol>
<p>所以实际上,除了在Python中使用amqp1.0之外,不能使用<code>partitionKey</code>值将事件发送到指定的EventHub分区。要使用amqp1.0,请参阅官方文档<a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-amqp-protocol-guide?toc=%2Fen-us%2Fazure%2Fevent-hubs%2FTOC.json&bc=%2Fen-us%2Fazure%2Fbread%2Ftoc.json" rel="nofollow noreferrer">^{<cd8>}</a>,并在页面上搜索<code>partition-key</code>,结果如下。在</p>
<p><a href="https://i.stack.imgur.com/iFapH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iFapH.png" alt="enter image description here"/></a></p>