【发布时间】:2022-11-11 05:56:50
【问题描述】:
我想使用 Python Blob 触发器作为持久函数客户端来触发一个协调的进程,但是我没有看到持久函数中的 blob 触发器的任何选项,任何人都可以指导我吗?
【问题讨论】:
标签: azure-functions azure-blob-storage azure-durable-functions
我想使用 Python Blob 触发器作为持久函数客户端来触发一个协调的进程,但是我没有看到持久函数中的 blob 触发器的任何选项,任何人都可以指导我吗?
【问题讨论】:
标签: azure-functions azure-blob-storage azure-durable-functions
如果要使用 Python Blob Trigger 作为持久函数客户端来触发编排流程,则需要二功能:
使用下面的脚本来创建blob trigger function:
[FunctionName("StartOrchestratorBlobTrigger")]
public async Task StartOrchestratorBlobTrigger(
[BlobTrigger("sample-workitems/{name}", Connection = "CloudSightStorage")]
Stream myBlob,string name,
[OrchestrationClient] DurableOrchestrationClient durableOrchestrationClient,ILogger log)
{
// get your blob content, and desrialize if you need and pass it orchestrator instead of stream as below
await durableOrchestrationClient.StartNewAsync("YourNewDurableFunction", myBlob);
}
在上述函数中,OrchestrationTrigger将用作您的持久功能的触发器。
去创造耐用功能,利用下面的示例脚本:
[FunctionName("YourNewDurableFunction")]
public async Task YourNewDurableFunction
(
[OrchestrationTrigger]
DurableOrchestrationContextBase orchestrationContext,ILogger logger)
{
// Call activity functions here.
}
如需更多详细信息,请参考以下链接:
Use durable function with blobstorage trigger and i get an error - Microsoft Q&A aakash-sharma 已回答
【讨论】:
你需要改变__init__.py和function.json的文件斑点触发器如下:
__init__.py:
import logging
import azure.functions as func
import azure.durable_functions as df
async def main(myblob: func.InputStream, starter: str):
logging.info("Python blob trigger function processed blob)
client = df.DurableOrchestrationClient(starter)
instance_id = await client.start_new('YourNewDurableFunction')
function.json:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "ContainerName/{name}",
"connection": "AZURE_STORAGE_CONNECTION_STRING"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
【讨论】: