简体   繁体   English

AWS SWF-工作流程的返回结果

[英]AWS SWF - Return result of workflow

I have started learning amazon web services with simple workflow service. 我已经开始通过简单的工作流服务学习亚马逊网络服务。 I have completed the eclipse setup for development and successfully completed the hello world workflow application from here . 我已经完成了Eclipse的开发设置,并从这里成功完成了hello world工作流应用程序。

For using the same application on web platform, I tried creating AWS web project and calling the workflow methods from servlet. 为了在Web平台上使用同一应用程序,我尝试创建AWS Web项目并从servlet调用工作流方法。 The servlet runs without any error and output is printed to console. 该Servlet可以正常运行,并且输出将打印到控制台。 If I want the workflow to return the string message which is printed on console, what changes are needed? 如果我希望工作流返回控制台上打印的字符串消息,需要进行哪些更改?

Same question posted at amazon aws forums . 在亚马逊AWS论坛上发布了同样的问题。 Their is no clear documentation on AWS Simple Workflow Framework. 他们还没有关于AWS Simple Workflow Framework的明确文档。 You can check here 你可以在这里查看

AWS Workflow executes Asynchronously so that why generated code return type is void. AWS Workflow 异步执行,因此生成的代码返回类型为何为空。 IF you want then you can get by using 如果您想要的话可​​以通过使用获得

GetWorkflowExecutionHistoryRequest historyRequest = new GetWorkflowExecutionHistoryRequest();
historyRequest.setDomain(domain);
historyRequest.setExecution(workflowExecution);
historyRequest.setReverseOrder(true);
History workflowExecutionHistory = service.getWorkflowExecutionHistory(historyRequest);

If you want result then Just create a thread and when result populates in method you will get data . 如果需要结果,则只需创建一个线程,当结果填充到方法中时,您将获取数据。 But this is not good way to run thread continuously. 但这不是连续运行线程的好方法。

What is your use case? 您的用例是什么? Workflow returning a value is usually a bad idea (unless it is a child workflow) as workflow is asynchronous and long running. 返回值的工作流通常是一个坏主意(除非它是子工作流),因为工作流是异步的并且可以长时间运行。 Console application that started it should be able to exit without affecting workflow execution. 启动它的控制台应用程序应该能够退出而不影响工作流程的执行。

The step that you need to do to return a value from a workflow are: 从工作流返回值所需执行的步骤是:

  • have the workflow declare that it's return value is a Promise containing the type that you want to return. 让工作流程声明其返回值是一个Promise,其中包含您要返回的类型。
  • have the workflow return a Promise (or a Settable) with the value that you want to return. 让工作流返回一个Promise(或Settable),并带有您要返回的值。
  • have the client check if the workflow is closed and complete using the DescribeWorkflowExecutionRequest API 让客户端使用DescribeWorkflowExecutionRequest API检查工作流程是否关闭并完成
  • have the client get the result from the workflow history using the GetWorkflowExecutionHistoryRequest API 让客户端使用GetWorkflowExecutionHistoryRequest API从工作流历史记录中获取结果
  • use the workflow's DataConverter to deserialize the result into the result object that you want. 使用工作流的DataConverter将结果反序列化为所需的结果对象。

Below is an example of all of those changes applied to the HelloWorld example provided by AWS. 以下是适用于AWS提供的HelloWorld示例的所有这些更改的示例。 The HelloWorld example below returns a value from the workflow and prints the value in the client. 下面的HelloWorld示例从工作流返回一个值,并在客户端中打印该值。

https://github.com/aquesnel/aws-sdk-java/commit/87a80b5946f02283faecaa7436828ecd1c43921c https://github.com/aquesnel/aws-sdk-java/commit/87a80b5946f02283faecaa7436828ecd1c43921c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM