gpt4 book ai didi

java - 如何在 camunda 中建模异步服务任务并在 Spring Boot 中实现

转载 作者:行者123 更新时间:2023-12-01 16:32:10 25 4
gpt4 key购买 nike

我在 Spring Boot 应用程序中使用 Camunda 作为 bpmn 引擎

主要思想:第一个进程在 Controller 中启动,响应返回到客户端后,第二个进程应该启动。我使用@Async(spring框架)来启动第二个进程,并且我有两个bpmn图: firstProcess secondProcess

这个想法的简单实现:

@RestController
public class SimpleController {
@Autowired
private CustomService asyncService;
@Autowired
private CustomService syncService;

@GetMapping(value = "/request")
public ResponseEntity<String> sendQuestion() {
//start process described in first.bpmn
syncService.startProcess("firstProcess");
//start process described in second.bpmn asynchronously
//controller responses to client without waiting for ending secondProcess
asyncService.startProcess("secondProcess");
return new ResponseEntity<>("OK", HttpStatus.OK);
}
}
@Service
public class AsyncService implements CustomService {

@Autowired
private RuntimeService runtimeService;

@Async
public void startProcess(String key) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
//
}
runtimeService.startProcessInstanceByKey(key);
}
}

问题:有没有一种方法可以在一个进程中完成这两个过程(如两个进程所示)?我应该如何在 Spring Boot 应用程序中实现这个? bothProcess

最佳答案

您需要使用Call Activity Task,将BPMN指定为CallActivity Type,并在Called Element字段中指定相应的流程ID在属性面板上。另外,不要忘记取消选中子流程的 Startable 复选框。

关于java - 如何在 camunda 中建模异步服务任务并在 Spring Boot 中实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62019615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com