Hello again @jonathan.lukas
Thank you for your great point.
As we checked your suggestion out, it’s not necessary to modify(or override) Engine Rest (MessageCorrelationResultWithVariableDto
). We could send our message with two VariableMap(for example processVariables
and correlationKeys
) easily. So just we need a new API method.
I have developed below source code on External Task project.
I have attached each modification separately
EngineClient.java
// public static final String SEND_MESSAGE = "/message";
public void sendMessage(ExternalTask externalTask, String message, VariableMap correlationKeys, VariableMap processVariables, Boolean all) throws EngineClientException {
SendMessageRequestDto payload = new SendMessageRequestDto(externalTask, message, correlationKeys, processVariables, all);
String resourceUrl = baseUrl + SEND_MESSAGE;
engineInteraction.postRequest(resourceUrl, payload, Void.class, xsrf);
}
ExternalTaskServiceImpl.java
@Override
public void sendMessage(ExternalTask externalTask, String message, VariableMap correlationKeys, VariableMap processVariables, Boolean all) {
try {
engineClient.sendMessage(externalTask, message, correlationKeys, processVariables, all);
} catch (EngineClientException e) {
throw handleException(e, "send message", true);
}
}
ExternalTaskService.java (interface)
/**
* Send Message
*
* @param message which message string that you need to send to engine
* @param correlationKeys indicates the master keys for correlation.
* @param processVariables provides related variables to the process.
* @param all specifies which params should be send (all or not).
*
* @throws NotFoundException if the task has been canceled and therefore does not exist anymore
* @throws NotAcquiredException if the task's most recent lock could not be acquired
* @throws ConnectionLostException if the connection could not be established
* @throws ValueMapperException
* <ul>
* <li> if an object cannot be serialized
* <li> if no 'objectTypeName' is provided for non-null value
* <li> if value is of type abstract
* <li> if no suitable serializer could be found
* </ul>
*/
void sendMessage(ExternalTask externalTask, String message, VariableMap correlationKeys, VariableMap processVariables, Boolean all);
In the end, I prepared a sample test and catch a successful response from the Engine.
public static void main(String[] args) {
// Personal Test
ExternalTaskClient client = ExternalTaskClient.create()
.baseUrl("http://10.1.2.51:8080/engine-rest")
.asyncResponseTimeout(10000) // long polling timeout
.build();
client.subscribe("charge-card")
.lockDuration(1000)
.handler((externalTask, externalTaskService) -> {
VariableMap correlationKeys = new VariableMapImpl();
correlationKeys.putValueTyped("aVariable", Variables.stringValue("aValue"));
VariableMap processVariables = new VariableMapImpl();
processVariables.putValueTyped("aVariable", Variables.stringValue("aNewValue", true));
processVariables.putValueTyped("anotherVariable", Variables.booleanValue(true, true));
externalTaskService.sendMessage(externalTask, "aMessage", correlationKeys, processVariables, null);
externalTaskService.complete(externalTask);
})
.open();
}
We could send our message (for example aMessage
) with correlation
and process
variables from the External Task to the Engine successfully.
It’s our pleasure if we could contribute to the External Task project.
Let me know your feedback
Best Regards,
Taha Arian