@HEss you can try this example:
Delegates::
@Slf4j
@Component
public class ProductEnquiryDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
FlowElement flowElement = execution.getBpmnModelElementInstance();
log.info("Flow Element Type::{}", flowElement.getElementType().getTypeName());
if (flowElement.getName().equals("Forward Message")) {
runtimeService.createMessageCorrelation("RECIEVE_ENQUIRY_MESSAGE")
.processInstanceBusinessKey(execution.getProcessBusinessKey())
.setVariable("text", execution.getVariable("text")).startMessageOnly().correlate();
} else {
runtimeService.createMessageCorrelation("RECIEVE_PRODUCT_MESSAGE")
.processInstanceBusinessKey(execution.getProcessBusinessKey())
.setVariable("reply", execution.getVariable("reply")).correlate();
}
}
}
@Slf4j
@Component
public class EnquiryLoggerDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
if(execution.getBpmnModelElementInstance().getName().equals("Log Reply Message")) {
log.info("Reply Message:{}", execution.getVariable("reply"));
}else {
log.info("Text Message:{}", execution.getVariable("text"));
}
}
}
Bpmn File: PRODUCT_ENQUIRY_PROCESS.bpmn (14.1 KB)