[英]How to dynamically read blob file from Azure Function Python
I want to be able to dynamically read the blob file (json) with Azure Function Python with the filename passed through Azure Event hub message.我希望能够使用 Azure Function Python 动态读取 blob 文件 (json),文件名通过 Azure 事件中心消息传递。 How can I do that with Azure Bindings?我如何使用 Azure 绑定来做到这一点?
function.json function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "eventHubTrigger",
"name": "events",
"direction": "in",
"eventHubName": "beta-api-intergration",
"connection": "receiverConnectionString",
"cardinality": "many",
"consumerGroup": "beta-api-consumer",
"dataType": "binary"
},
{
"name": "betablob",
"type": "blob",
"path": "swuploads/{filename}.json",
"connection": "AzureWebJobsStorage",
"direction": "in"
}
]
}
init .py初始化.py
def main(events: List[func.EventHubEvent], betablob: func.InputStream):
well.login(user,pwd)
for event in events:
logging.info('Python EventHub trigger processed an event: %s', event.get_body().decode('utf-8'))
###msg contains the file name I want to load in blob
msg=parse_msg(event)
####how do I pass the file name here ?
data=load_blob(betablob)
Under normal circumstances, dynamic binding can be realized indirectly by passing in json format input (or trigger).一般情况下,可以通过传入json格式的输入(或触发)间接实现动态绑定。
For example, send message like this:例如,发送这样的消息:
{
"filename":"test"
}
And then binding will get the value 'test'.(This only works for language like python which use declarative bindings.)然后绑定将获得值“test”。(这仅适用于使用声明性绑定的语言,如 python。)
But it seems that event hub cannot specify the format of the incoming information, so pure binding cannot be achieved.但是event hub好像不能指定传入信息的格式,所以无法实现纯绑定。 You need the python-based Azure SDK to implement dynamic binding.需要基于python的 Azure SDK 来实现动态绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.