Send & Receive Message using Expression

I have been trying to create an expression in the Camunda Modeller that will allow a message to be sent to another workflow triggering it using the message start event. I also though want to be able to send a message back to the instance that sent the original message.

I have been using an expression like the one below.

${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(“myMessage”).correlateWithResult()}

I understand that I need to correlate the instance that sends the message with the new instance that will send a message back.
I’m not sure how to send the processInstanceId or business key along with any variables I may wish to pass.

I have had some success triggering the start of another workflow using the message start event, but when I try and send a message back when there is more than one instance running I get a conflict. How to I set up two way communication between two instances of two workflows?

Passing business key and/or variables you can do as follow:

${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation("yourMessageName").setVariables(yourVariablesMap).processInstanceBusinessKey("yourBusinessKey").correlate()}

Correlation will be done with business key. If you need to correlate by more variables, then use correlation keys (but it’s much slower).

1 Like