用于启动流程实例的REST API正在保留请求,直到流程实例完成

时间:2019-01-17 09:18:21

标签: rest activiti

我正在使用Activiti版本6。

我从activiti-app创建了BPMN流程。
然后,我想使用API​​从 activiti-rest.war 开始该过程。

http://localhost:8080/activiti-rest/service/runtime/process-instances

request body :

 {

   "processDefinitionKey":"cep_dispatch_process",
   "businessKey":"myBusinessKey",
     "returnVariables": false
}

header :
Content-Type:application/json

我在LOG进程中看到的是在tomcat线程中启动的。 引用最新的GitHub代码:

Activiti-activiti-6.0.0\modules\activiti-rest\src\main\java\org\activiti\rest\service\api\runtime\process\ProcessInstanceCollectionResource.java

当我看到方法时,

@RequestMapping(value = "/runtime/process-instances", method = RequestMethod.POST, produces = "application/json")
  public ProcessInstanceResponse createProcessInstance(@RequestBody ProcessInstanceCreateRequest request, HttpServletRequest httpRequest, HttpServletResponse response) {

我可以看到进程正在启动,而不是等待进程完成,HTTP响应是201。我可以理解,请求没有等待进程实例完成。

instance = processInstanceBuilder.start();

response.setStatus(HttpStatus.CREATED.value());

请参考下面的日志,我可以看到进程正在服务器线程中执行,请求正在等待直到进程完成。

276-DEBUG 17-01-2019 14:12:07,177- (http-nio-8080-exec-3) ExecutionEntityManagerImpl: Child execution Execution[ id '130023' ] - parent '130021' created with parent 130021
241-DEBUG 17-01-2019 14:12:07,178- (http-nio-8080-exec-3) ContinueProcessOperation: Executing boundary event activityBehavior class org.activiti.engine.impl.bpmn.behavior.BoundaryTimerEventActivityBehavior with execution 130023
171-DEBUG 17-01-2019 14:12:07,202- (http-nio-8080-exec-3) ContinueProcessOperation: Executing activityBehavior class org.activiti.engine.impl.bpmn.behavior.SubProcessActivityBehavior on activity 'sid-1A2A8DF5-764A-4960-8E5D-F347DC10207C' with execution 130021
276-DEBUG 17-01-2019 14:12:07,203- (http-nio-8080-exec-3) ExecutionEntityManagerImpl: Child execution Execution[ id '130025' ] - parent '130021' created with parent 130021
63-DEBUG 17-01-2019 14:12:07,203- (http-nio-8080-exec-3) DefaultActivitiEngineAgenda: Operation class org.activiti.engine.impl.agenda.ContinueProcessOperation added to agenda
70-DEBUG 17-01-2019 14:12:07,203- (http-nio-8080-exec-3) CommandInvoker: Executing operation class org.activiti.engine.impl.agenda.ContinueProcessOperation 

请求不得等待过程完成。

我该如何解决,请求启动流程一定不能等待流程实例完成。

如您在以下响应中所见:

{"id":"130028",
"url":"http://localhost:8080/activiti-rest/service/runtime/process-instances/130028",
"businessKey":"myBusinessKey",
"suspended":false,
"ended":true,
"processDefinitionId":"cep_dispatch_process:13:125033",
"processDefinitionUrl":"http://localhost:8080/activiti-rest/service/repository/process-definitions/cep_dispatch_process:13:125033"
,"processDefinitionKey":"cep_dispatch_process",
"activityId":null,
"variables":[],
"tenantId":"",
"name":null,
"completed":true
}

API仅在流程完成后才返回,我在服务任务中添加了2分钟的延迟,可以看到请求将等待。

1 个答案:

答案 0 :(得分:1)

我不是Activiti的专家,但作为最简单的解决方案,我建议activate Async executor并将Asynchronous Continuations用于您的服务任务。这样可以解决您的问题。 Activiti的行为是可以预料的,因为直到状态持久化到DB之前,它无法确定是否创建了该进程(因为事务可能由于DB错误而回滚)