【问题标题】:Using Python Blob Trigger as Durable Client in Azure在 Azure 中使用 Python Blob 触发器作为持久客户端
【发布时间】:2022-11-11 05:56:50
【问题描述】:

我想使用 Python Blob 触发器作为持久函数客户端来触发一个协调的进程,但是我没有看到持久函数中的 blob 触发器的任何选项,任何人都可以指导我吗?

【问题讨论】:

    标签: azure-functions azure-blob-storage azure-durable-functions


    【解决方案1】:

    如果要使用 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 已回答

    Durable Function Blob Trigger - Stack Overflow 塞巴斯蒂安·阿查兹

    Bindings for Durable Functions - Azure | Microsoft Docs

    【讨论】:

    • 谢谢您的回复,请问您有python脚本吗?这将是完美的。
    • 请参阅此链接以获取python script
    【解决方案2】:

    你需要改变__init__.pyfunction.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"
        }
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-12
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2021-02-26
      • 2020-11-26
      相关资源
      最近更新 更多