try {
ObjectMapper objectMapper = getObjectMapper();
Map<String, Object> correlationKeys = VariableValueDto.toMap(messageDto.getCorrelationKeys(), processEngine, objectMapper);
Map<String, Object> processVariables = VariableValueDto.toMap(messageDto.getProcessVariables(), processEngine, objectMapper);
MessageCorrelationBuilder correlation = runtimeService
.createMessageCorrelation(messageDto.getMessageName())
.setVariables(processVariables)
.processInstanceBusinessKey(messageDto.getBusinessKey());
if (correlationKeys != null && !correlationKeys.isEmpty()) {
for (Entry<String, Object> correlationKey : correlationKeys.entrySet()) {
String name = correlationKey.getKey();
Object value = correlationKey.getValue();
correlation.processInstanceVariableEquals(name, value);
}
}
if (!messageDto.isAll()) {
correlation.correlate();
} else {
correlation.correlateAll();
}
} catch (RestException e) {
String errorMessage = String.format("Cannot deliver message: %s", e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);