如何使用ELSA工作流引擎同步执行工作流程
ELSA Workflow支持工作流的异步执行,因此我们无法将结果当作结果,线程执行的工作流执行以及立即响应。因此,完成工作流执行后,我将无法获得工作流的实际输出。因此,是否可以同步执行工作流执行,以便我可以获取最终输出。
Elsa workflow supports asynchronously execution of workflow, so we can't get the result on spot, workflow execution performed by a thread, and response back instantly. So after completing workflow execution i'm unable to get actual output of workflow. So is there any way to perform workflow execution synchronously so that I can get the final output.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
iworkflowRunner.runworkFlowAsync
同步运行工作流,该返回runworkflowResult
,其中包含已执行的WorkflowInstance
,其中包含由输出设置的输出工作流程(如果有)。RunWorkFlowAsync
采用以下参数:iworkflofllueprint
- 工作流蓝图运行。WorkFlowInstance
- 工作流蓝图的工作流实例。ActivationId
- 可选。如果您的工作流程具有多个启动活动,则需要指定要使用哪个活动。WorkFlowInput
- 可选。如果您的工作流程期望输入,那么您就是您提供的。要获取工作流蓝图,请使用
iworkflowRegistry
按名称或类型查找工作流(如果您使用Fluent API构建工作流程,则更方便。例如,如果您有一个名为“ Helloworld”的工作流,这就是您获得工作流蓝图的方式:
创建一个工作流实例,尽管您可以简单地使用其构造函数实例化新的
WorkflowInstance
,这是最简单的方法是要使用iWorkflowFactory
像这样:使用Ready的WorkFlow蓝图和WorkFlow实例,您现在可以运行工作流程:
作为此低级工作流程执行的替代方案,您也可以使用一项一项艰巨的高级服务。
例如,如果您使用Fluent API(即
iWorkflow
实现)创建了一个工作流,称为helloworldworkflow
,则可以使用ibuildsandStartsworksworkflow ,这样:
这将完成我之前为您解释的步骤(并同步运行工作流程)。
另一种方法是使用称为
iworkflowlaunchpad
的高级服务,该服务具有各种方法来定位要执行的工作流(或工作流)。例如,如果您知道要同步执行的工作流定义ID,则是这样做的方法:
You can run your workflow synchronously using
IWorkflowRunner.RunWorkflowAsync
, which returns aRunWorkflowResult
that contains the executedWorkflowInstance
, which contains output that was set by the workflow, if any.The
RunWorkflowAsync
takes the following parameters:IWorkflowBlueprint
- the workflow blueprint to run.WorkflowInstance
- a workflow instance of the workflow blueprint.ActivityId
- Optional. If your workflow has more than one starting activity, you need to specify which one to use.WorkflowInput
- Optional. If your workflow expects input, this is where you provide it.To get a workflow blueprint, use
IWorkflowRegistry
to find a workflow by name or by type (which is more convenient in case you have your workflow built using the fluent API).For example, if you have a workflow named "HelloWorld", this is how you get the workflow blueprint:
To create a workflow instance, although you could simply instantiate a new
WorkflowInstance
using its constructor, the simplest way is to useIWorkflowFactory
like this:With both the workflow blueprint and workflow instance at the ready, you can now run the workflow:
As an alternative to this low-level prepping of workflow execution, you can also use a higher-level service that does all this on one go.
For example, if you have a workflow created using the fluent API (i.e. some
IWorkflow
implementation) calledHelloWorldWorkflow
, then you can run the workflow usingIBuildsAndStartsWorkflow
, like this:That will do the steps I explained earlier for you (and run the workflow synchronously).
Yet another way is to use the higher-level service called
IWorkflowLaunchpad
, which has various methods to locate the workflow (or workflows) you want to execute.For example, if you know the workflow definition ID you want to execute synchronously, here's how you would do it: