有没有一种方法可以通过编程方式从 WebJob 中的另一个函数调用 WebJob 函数,并且仍然可以进行输出绑定?

Is there a way to programmatically invoke a WebJob function from another function within the WebJob and still have the output binding work?

代码如下:

[return: Table("AnalysisDataTable", Connection = "TableStorageConnection")]

public static async Task<OrchestrationManagerAnalysisData> InputQueueTriggerHandler(
        [QueueTrigger("DtOrchestrnRequestQueueName", 
                      Connection = "StorageQueueConnection")] string queueMsg,
        [OrchestrationClient] DurableOrchestrationClient client, ILogger logger) 
   {

        logger.LogInformation($"***DtOrchestrationRequestQueueTriggerHandler(): queueMsg = {queueMsg}");
        await ProcessInputMessage(queueMsg, client, logger);

    //  Below is where the code goes to format the TableStorage Entity called analysisData.

    // This return causes the above output binding to be executed, saving analysis data to
    // Table Storage.
    return analysisData;
}

以上代码运行良好,并将分析数据保存到 TableStorage。

然而,当我将输出绑定属性放在以编程方式调用的 ProcessInputMessage() 上时 而不是作为触发器的结果调用一切正常,除了没有数据输出 到 Table 存储。

    [return: Table("AnalysisDataTable", Connection = "TableStorageConnectionName")]

public static async Task<OrchestrationManagerAnalysisData> 
        ProcessInputMessage(string queueMsg, DurableOrchestrationClient client, ILogger logger)
    {
    //  Do the processing of the input message.


    //  Below is where the code goes to format the TableStorage Entity called analysisData.

    // This return causes the above output binding to be executed, saving analysis data to
    // Table Storage.
    return analysisData;
}

问题当从 WebJob 中的另一个函数以编程方式调用时,是否有办法导致输出绑定到 "trigger"?

我喜欢输出绑定的省力特性,并希望尽可能地利用它们,同时还拥有分解良好的代码,即每个方法中的紧密内聚。

谢谢, 乔治

is there a way to cause an output binding to "trigger" when invoked programatically from another function within the WebJob?

简而言之,没有

您使用在函数中应用输出绑定属性的 return value of the function 发送数据。所以,如果你想调用另一个函数并将数据写入 Table 存储。

想要实现你想要的想法,需要覆盖return方法。但是,它是一种包集成方法,所以我建议您可以使用将客户实体插入到 Table 存储中的 TableOperation 对象。

TableOperation insertOperation = TableOperation.Insert(customer1);

// Execute the insert operation.
table.Execute(insertOperation);

更多细节,你可以参考这个article