java - 如何在camunda中建模异步服务任务并在spring boot中实现
问题描述
我在我的 Spring Boot 应用程序中使用 Camunda 作为 bpmn 引擎
主要思想: 第一个进程在控制器中启动,响应返回给客户端后,第二个进程应该启动。我使用@Async(spring framework)来启动第二个进程,我有两个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 应用程序中实现这一点? 两个过程
解决方案
您需要在属性面板上的字段中Call Activity Task
指定BPMN
asCallActivity Type
和相应的进程 ID 。Called Element
也不要忘记取消Startable
选中子流程的复选框。
推荐阅读
- c - 如何使用递归正确打印城市?
- javascript - 如何在 NextJs 中多次循环单个 const
- rust - 调用 setter 后,借用检查器不会让我调用 getter
- delphi - Delphi如何在使用ShellExecute时正确设置变量
- css - 使用 CSS 动画和 SVG 为其他人的 SVG 而不是我的 SVG 制作平滑的正弦波?
- flutter - 为什么一个函数可能不会在颤振中在 initState(){ super.initState()} 中被调用,但如果稍后在同一页面中调用则工作得很好?
- python - 在 gitlab ci 管道/python 3 alpine 图像中找不到 sphinx-build 命令
- selenium - 在单独的选项卡中打开链接
- flutter - Flutter如何通过屏幕打印值?
- python - 在python中对齐unicode字符的问题