Send variable together with message in camunda

Viewed 2399

I have a receiving process which has an intermediate message event waiting for a message send by a sending process.

I am already able to trigger the intermediate message event by the following delegate code in my sending process:

RuntimeService runtimeService = ProcessEngines
        .getDefaultProcessEngine()
        .getRuntimeService();
MessageCorrelationResult result = runtimeService
        .createMessageCorrelation("my-message-name")
        .setVariable("customer", customer)    //trigger instance where customer matches
        .correlateWithResult();

My question is: How can I send a variable from the sending process to the receiving process combined with the message? Are there any best practices?

This is what I haved tried so far:

// Set the variable after the correlation
runtimeService.setVariable(result.getProcessInstance().getId(),
    "variableToSend", variableToSend);

I try to retrieve the variable in a JavaDelegate like this:

// Access the sent variable
Double sendByOtherProcess = (Double) delegate.getVariable("variableToSend");
// sendByOtherProcess == null

Interestingly enough, it is possible to retrieve variableToSend in an embedded form via JavaScript in the receiving process.

I read that it might be an isse due to synchron/asynchron behavior?

Any help appreciated.

1 Answers
Related