Python 3.x 如何使用Python作为实时数据流,逐个记录地将CSV文件发送到Azure事件中心

Python 3.x 如何使用Python作为实时数据流,逐个记录地将CSV文件发送到Azure事件中心,python-3.x,azure,csv,azure-eventhub,Python 3.x,Azure,Csv,Azure Eventhub,我已尝试使用Microsoft Documentation()中提供的示例代码将消息发送到事件中心。我是否可以使用相同的代码将CSV文件记录发送到事件中心更新0904:如果您要发送一批事件数据,请遵循以下代码: ADDRESS = "amqps://xxx.servicebus.windows.net/xxx" # SAS policy and key are not required if they are encoded in the URL USER = "RootManageShare

我已尝试使用Microsoft Documentation()中提供的示例代码将消息发送到事件中心。我是否可以使用相同的代码将CSV文件记录发送到事件中心

更新0904:如果您要发送一批事件数据,请遵循以下代码:

ADDRESS = "amqps://xxx.servicebus.windows.net/xxx"

# SAS policy and key are not required if they are encoded in the URL
USER = "RootManageSharedAccessKey"
KEY = "xxx"

#this generator method is just an example, please implement your own logic in the data_generator
def data_generator():
    for i in range(5):
        yield b"hello world!!! hhhhhhhhheee"


if not ADDRESS:
    raise ValueError("No EventHubs URL supplied.")

# Create Event Hubs client
client = EventHubClient(ADDRESS, debug=False, username=USER, password=KEY)
sender = client.add_sender(partition="0")
client.run()  

#send the batch of eventData
data = EventData(batch=data_generator())
sender.send(data)

如果您的意思是发送.csv文件中每个单元格中的每条消息,
您可以编写自己的逻辑来获取.csv文件中的每条消息
(请尝试使用谷歌搜索该实现),然后使用
for
循环将它们发送到事件中心

只需对中的代码进行一些更改:


关于逐条记录,您的意思是在.csv文件的每个单元格中发送每条消息吗?没有。一个记录一个记录意味着一次发送整个记录或一组记录。你有什么问题?您不知道如何从.csv获取记录?如果可以从.csv文件中获取记录,则可以使用send方法发送该记录。或者别的什么?或者你的意思是发送一批事件数据?如果是这样的话,请参考下面更新的部分。你的问题解决了吗?
logger = logging.getLogger("azure")

ADDRESS = "amqps://xx.servicebus.windows.net/xxx"

# SAS policy and key are not required if they are encoded in the URL
USER = "RootManageSharedAccessKey"
KEY = "xxxx"

if not ADDRESS:
    raise ValueError("No EventHubs URL supplied.")

# Create Event Hubs client
client = EventHubClient(ADDRESS, debug=False, username=USER, password=KEY)

#if you ommit the parameter partition="0", the events will be distributed to all available partitions via round-robin
sender = client.add_sender(partition="0")
client.run()  

#you should write your own logic to fetch each message in .csv file
#you then can use for loop to send each message in .csv like below, the following is just an test example
for i in range(10):
    print("Sending message: {}".format(i))
    sender.send(EventData("this is msg: "+str(i)))