How to send Properties details in EventHub message using python?

后端 未结 3 390
温柔的废话
温柔的废话 2021-01-24 17:20

I am referring to this article \"https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-python-get-started-send\" related to sending messages to EventHub using Python.

3条回答
  •  独厮守ぢ
    2021-01-24 18:22

    Found solution to this, yes we can use "application_properties" to send "properties" of message. This is my sample code that worked:

    from azure.eventhub import EventHubClient, Receiver, Offset, Sender, EventData
    from uamqp import Message
    
    ADDRESS = "amqps://<>.windows.net/<>"
    USER = "RootManageSharedAccessKey"
    KEY = "<>"
    
    client = EventHubClient(ADDRESS, debug=True, username=USER, password=KEY)
    Sender = client.add_sender(partition="0")
    client.run()
    
    event = EventData(body="TESTTWO:100, Temperature:-127.0")
    event.application_properties = {"Type": "iPhone"}
    Sender.send(event)
    

提交回复
热议问题