why is it not possible in camunda to correlate a message directly from intermediate throwing message event without writing java code but defining a message to throw on bpmn event.
The semantic could be to correlate to receivers in same process instance. So if a receiver exits in same process instance this would directly work without writing java code.
Ok this could be a reason.
I found a simple solution for us and would like to share the code. Its a simple ExecutionListener activated with camunda reactor. It checks if intermediateThrowEvent ha a message and correlates it to all receivers in process instance with same business Key.
@Log4j
@CamundaSelector(type = "intermediateThrowEvent", event = ExecutionListener.EVENTNAME_START)
public class CorrelateMessageExecutionListener implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) throws Exception {
IntermediateThrowEvent event =(IntermediateThrowEvent)execution.getBpmnModelElementInstance();
Optional<MessageEventDefinition> messageEventDefinitionOptional = event.getEventDefinitions().stream()
.filter((ed) -> ed instanceof MessageEventDefinition)
.map((ed) -> ((MessageEventDefinition)ed))
.findFirst();
messageEventDefinitionOptional.ifPresent((messageEventDefinition) -> {
if(messageEventDefinition.getMessage()!=null){
if(execution.getProcessBusinessKey()!=null){
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
String messageName = messageEventDefinition.getMessage().getName();
runtimeService.createMessageCorrelation(messageName).processInstanceBusinessKey(execution.getProcessBusinessKey()).correlateAll();
}else{
log.info(String.format("No message is thrown from execution=%s because no businessKey is defined in process instance",execution.getId()));
}
}
});
}
no that is no good solution for me because I dont want a process instance overall broadcast event but a event which is only delegated to receivers in same process instance.