Main idea: First process is started in the controller, and after the response is returned to the client, the Second process should start. I do this using @Async(spring framework) to start the second process and I have two bpmn diagram (you can find attached first.bpmn, second.bpmn is the same as first.bpmn)
@RestController
public class SimpleController {
@Autowired
private CustomService asyncService;
@Autowired
private CustomService syncService;
@GetMapping(value = "/request")
public ResponseEntity<String> sendQuestion() {
syncService.startProcess("firstProcess");
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) {
runtimeService.startProcessInstanceByKey(key);
}
}
Question:
Is there a way to do all this in one process (you can find example attached both.bpmn) and how should this implement? first.bpmn (2.3 KB) both.bpmn (3.9 KB)
@Yury, you can use Call activity/Message start Event to initiate a processes asynchronously by enabling camunda:asyncBefore="true" in the startevent for both the processes. Check the configurations in the image and attached bpmn example for reference.
@aravindhrs thanks for the answer. It helped me a lot!
Some additional for the solution to my issue:
I want to get a response from the controller when firstProcess is done and only after that start secondProcess so I need to enable camunda:asyncBefore=“true” only in the startevent for the second process.
@aravindhrs do you know way to do it in one bpmn diagram? Because I need to use three diagrams to do this action, but actually I want to have one diagram for one business process(my business process contains firstProcess and secondProcess(async)) if it is possible.
@Yury, in the main bpmn just use call activity like @aravindhrs said and put there async thing, to complete the transaction, you will get response that is everything ok, and next step you putting on the engine meaning he will start the another process. If you need to give a context to the child process, do it over variables, see the attached bpmn.