具有事件集线器的Azure功能编排



我想用typescript执行多个函数的编排,但我的问题是我正在侦听现有的azure事件中心和事件的输出,我想将其传递给另一个azure函数。然后我必须将相同的数据传递给2rd函数,以此类推…

函数将按顺序执行。

  1. 从事件中心获取数据,该事件中心侦听所有分区的事件中心,这是函数0
  2. 将事件集线器(函数0(数据传递给另一个httptrigger函数1
  3. 将函数1的数据获取到函数2并传递给函数2

你能用Azure功能+typescript 提出解决方案吗

谨致问候,Abhi

通过使用持久函数并行执行多个作业。根据您的要求,您需要将函数值作为req传递给客户端函数,随后它将触发编排函数。

module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req, instanceId);
};

在编排函数中,您需要调用活动函数,以便将事件中心值的输出传递给另一个函数。

const df = require('durable-functions');
module.exports = df.orchestrator(function*(context){
// your code here
// Get input from the client that started
// get event hub values here
const Eventhub_value = context.df.getInput();
// Call Activity that fetches all lists that arent hidden, and wait for it to finish
const Fun1_op = yield context.df.callActivity("Function_1", Eventhub_value); 
const output = [];
output.push(yield context.df.callActivity("Function_2", Fun1_op));
}
// Here we could save the result to some DB if we want to
// yield context.df.callActivity('SaveItems', output);
// For this example we just log the result
context.log(JSON.stringify(output));
return context.instanceId;
});

以同样的方式,您可以通过使用Typescript的持久函数来实现。

参考博客&文件获取更多信息

最新更新