Azure 函数 Python

编程入门 行业动态 更新时间:2024-10-28 14:34:10
本文介绍了Azure 函数 Python |将带有属性的 EventData 消息发送到事件中心输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个 Azure python 函数,该函数被触发,然后生成多个传出消息.我需要将 EventData (body + properties) 消息发送到 Eventhub.到目前为止,我还没有找到任何方法来使用 EventHub 输出绑定向传出消息添加属性.似乎输出字符串被放入body"属性中.

I am writing an Azure python function that is triggered and then generates multiple outgoing messages. I need to send EventData (body + properties) messages to an Eventhub. Thus far I have not found any way to do add properties to an outgoing message using the EventHub output bindings. It appears that the output string is put into the "body" property.

我看到的一个可能的解决方案是将 EventHubClient 写入函数中,但这真的是让属性随消息一起发送的最有效方法吗?那为什么会有输出绑定呢?

One possible solution that I see is to write an EventHubClient into the function, but is that really the most effective way to get properties send with the message? Why would there be output bindings then?

我的function.json文件是:

My function.json file is:

{ "type": "eventHub", "name": "outputHub", "eventHubName": "test", "connection": "TestSendConnection", "direction": "out" }

这是我的代码:

def main(events: func.EventHubEvent, referenceInput: func.InputStream, outputHub: func.Out[str]): logging.info('Send an output event to eventhub') evt_data_list = [] for k in range(0,10): evt_data = EventData("Sample Body") evt_data.properties['EventType'] = "log" evt_data_list.append(evt_data) logging.info('Send an output event to eventhub') import random outputHub.set("[" + ",".join([str(evt) for evt in evt_data_list]) + "]")

我正在使用 Azure 事件中心资源管理器监视传入的消息,我收到了多条消息,但它们以以下格式到达.对于外部解析器,我需要将正文部分和属性部分分开.

I am monitoring the incoming messages with the Azure Event Hub Explorer and I receive multiple messages, but they arrive in the following format. I need the body and the properties sections to be separate for the external parser.

{ "body": { "body": "Sample Body", "properties": { "EventType": "log" } }, "enqueuedTimeUtc": "2020-06-09T17:59:04.803Z", "offset": "1335734859528", "sequenceNumber": 4995022 }

推荐答案

目前恐怕没有办法使用 EventHub 输出绑定为传出消息添加属性.

Currently I am afraid there is no way to add properties to an outgoing message using the EventHub output bindings.

解决方法是在函数内部使用 EventHub SDK.

The workaround is using EventHub SDK inside the function.

参考:

Microsoft Azure SDK for Event Hubs(Python)

更多推荐

Azure 函数 Python

本文发布于:2023-11-07 14:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   Azure   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!