首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将对象从触发器传递到编排和活动函数

如何将对象从触发器传递到编排和活动函数
EN

Stack Overflow用户
提问于 2019-08-05 14:50:08
回答 1查看 2.2K关注 0票数 1

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

我尝试将它包含在orchestra函数的参数中,但出现错误

HTTP触发器

代码语言:javascript
复制
#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);
}

Orchestra函数

代码语言:javascript
复制
#load "../Shared/jsonObject.csx"
[FunctionName("Orchestra")]
public static async void Run(DurableOrchestrationContext context)
{   

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

活动功能尚未实现

代码语言:javascript
复制
#load "../Shared/jsonObject.csx"
public static string Run(jsonObject bsObj)
{
return  "done";

}

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

EN

回答 1

Stack Overflow用户

发布于 2019-08-06 15:07:19

请尝试运行以下代码

HTTP触发器函数。

代码语言:javascript
复制
    [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);
    }

编排功能

代码语言:javascript
复制
        [FunctionName("Orchestra")]
    public static async Task RunOrchestrator(
        [OrchestrationTrigger] DurableOrchestrationContext context)
    {
        var bsObj = context.GetInput<JObject>();
        var output = await context.CallActivityAsync<JObject>("checkConditions", bsObj);
    }    

活动函数

代码语言:javascript
复制
        [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,对于HTTP触发函数,我引用了这个doc

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57353486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档