azure - 如何将对象从触发器传递到 Orchestra 和事件函数

标签 azure azure-durable-functions

我有调用 Orchestra 函数的 HTTP 触发器。在 HTTP 触发函数中,我收到 json 字符串,并将其反序列化为 object 。但是我不知道如何将此对象传递给 Orchestra 函数或事件函数。

我尝试将其作为管弦乐队函数的参数包含在内,但它给了我错误

HTTP 触发器

#load "../Shared/jsonObject.csx"
public static async Task<HttpResponseMessage> Run(
HttpRequestMessage req,
DurableOrchestrationClient starter,
string functionName,
ILogger log)
{

HttpContent requestContent = req.Content;
string jsonContent = requestContent.ReadAsStringAsync().Result;
jsonObject bsObj = JsonConvert.DeserializeObject<jsonObject>      (jsonContent);  

// Pass the function name as part of the route 
string instanceId = await starter.StartNewAsync("Orchestra", bsObj);

log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

return starter.CreateCheckStatusResponse(req, instanceId);
}

管弦乐队功能

#load "../Shared/jsonObject.csx"
[FunctionName("Orchestra")]
public static async void Run(DurableOrchestrationContext context)
{   

var output = await context.CallActivityAsync<int>("checkConditions", bsObj);
}

事件功能尚未实现

#load "../Shared/jsonObject.csx"
public static string Run(jsonObject bsObj)
{
return  "done";

}

[错误] run.csx(19,74): 错误 CS0103: 当前上下文中不存在名称“bsObj”

最佳答案

请尝试运行以下代码

HTTP触发功能。

    [FunctionName("HttpTriggerCSharp")]
    public static async Task<HttpResponseMessage> Run(
        [HttpTrigger(AuthorizationLevel.Function, "post")]HttpRequestMessage req,
        [OrchestrationClient]DurableOrchestrationClient starter,
        ILogger log)`
    {

        HttpContent requestContent = req.Content;
        string jsonContent = requestContent.ReadAsStringAsync().Result;
        JObject bsObj = JsonConvert.DeserializeObject<JObject>(jsonContent);
        // Pass the function name as part of the route 
        string instanceId = await starter.StartNewAsync("Orchestra", bsObj);
        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
        return starter.CreateCheckStatusResponse(req, instanceId);
    }

编排功能

        [FunctionName("Orchestra")]
    public static async Task RunOrchestrator(
        [OrchestrationTrigger] DurableOrchestrationContext context)
    {
        var bsObj = context.GetInput<JObject>();
        var output = await context.CallActivityAsync<JObject>("checkConditions", bsObj);
    }    

事件功能

        [FunctionName("checkConditions")]
    public static string SayHello([ActivityTrigger] JObject bsObj, ILogger log)
    {
        //Assign input value to any variable
        var json = bsObj;
        //Logic of the code
        return "done";
    }    

我引用了这个doc对于持久功能扩展和此doc用于 HTTP 触发功能。

关于azure - 如何将对象从触发器传递到 Orchestra 和事件函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57353486/

相关文章:

azure - 管理证书不在云中

c# - Azure持久功能: Fan Out vs. Parallel.ForEachAsync

python - Azure Durable 函数 python DurableOrchestrationContext get_input 返回 null

azure - 尝试在 Linux 虚拟机上的 Azure CLI 中创建虚拟机时出现响应错误

c# - Azure移动服务列表和API管理列表的API

sql - 如何在azure中定期运行sql查询?

node.js - 使用 Azure NodeJS Functions 下载平均 50kB 的 100,000 个文件的最快方法是什么?

postgresql - 用于向 Postgres DB 批量插入的 Azure 持久功能

c# - 如何避免 Azure 持久函数中的 PopReceiptMismatch 错误

azure - 如何在应用程序中使用 azure 应用程序服务环境变量?