Anyone knows how to send a message to Azure event hub with amqp in python? I need to send the message with partition key(not the partition id). Thanks very much.
According to the section Use of partition keys
of the offical document Partitioned queues and topics
, as below, you can send a message with partition key via set the PartitionKey
property of the message.
PartitionKey: If a message has the BrokeredMessage.PartitionKey property but not the BrokeredMessage.SessionId property set, then Service Bus uses the PartitionKey property as the partition key. If the message has both the SessionId and the PartitionKey properties set, both properties must be identical. If the PartitionKey property is set to a different value than the SessionId property, Service Bus returns an invalid operation exception. The PartitionKey property should be used if a sender sends non-session aware transactional messages. The partition key ensures that all messages that are sent within a transaction are handled by the same messaging broker.
For using Python, the steps as below.
pip install python-qpid-proton
.Here is my sample code as reference.
from proton import Messenger, Message
messenger = Messenger()
message = Message()
message.address = "amqps://<shared_access_policy_name>:<shared_access_policy_key>@<your-servicebus-namespace>.servicebus.windows.net/<your-eventhub-name>"
message.properties = {
"PartitonKey" : "<a partitonKey you want>",
}
message.body = u"This is a text string"
messenger.put(message)
messenger.send()
Please see the proton.Message
class reference here.
Hope it helps.