首页 > 解决方案 > 如何在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 应用程序中实现这一点? 两个过程

标签: javaspring-bootcamunda

解决方案


您需要在属性面板上的字段中Call Activity Task指定BPMNasCallActivity Type和相应的进程 ID 。Called Element也不要忘记取消Startable选中子流程的复选框。


推荐阅读