Message Correlation function

Hi everyone

when should we use
void correlateMessage(String messageName, String businessKey ?

what is the difference between this function and createMessageCorrelation() ?

Hi @mrdavoodi64 ,

createMessageCorrelation() is used to define a complex message correlation.
so you can build specific correlation logic as needed.

Below are two different variants constructed through createMessageCorrelation() method

  .setVariable("invoiceId", "123456") 

The above 1’st variant is equivalent to below call using correlateMessage method
correlateMessage("myMessage", myMessage.getOrderId().toString());

Thanks @hassang

but when I use the following expression in camunda modeler


I will get the following error:

“can not coerce from class java.lang.string to interface”

Hi @mrdavoodi64,

Could you please share your model or the exact used expression

yes this is my sample model

I used a static number “123456” as business key for testing purpose.diagram_1.bpmn (5.9 KB)

Hi @mrdavoodi64 ,

You have two issues in your model.

  • Message boundary event has the value of “myMessage” for message name whereas the value passed for messageName parameter of correlateMessage method is “MyMessage”

  • Both tasks (Task 1 & Task 2) are undefined tasks. Boundary event means that while the activity is running, the message boundary event is listening for named message but since Task 1 is undefined task then this will never happen since undefined task is considered as a pass-through activity.

Try below attached model in which Task 1 & Task 2 are set as User Tasks
diagram_1.bpmn (5.9 KB)

Notice: the model is valid only for testing purposes since completing Task 1 before Task 2 will lead to an error.

Hi @hassang
Thanks for your response, but the issue is still remained,

This is the error I get in the model that you have uploaded :

“can not coerce from class java.lang.string to interface”

Hi @mrdavoodi64,

Have you supplied the value of “123456” as businessKey on process start?

Please try below scenario

  • Start a new process instance with the value “123456” supplied as businessKey.

  • Complete Task 2.

I have tried the above scenario and it worked perfectly.

The reason you get this error is because in general expression language doesn’t allow method overloading.
In there are the following methods
void correlateMessage(String messageName, String businessKey);
void correlateMessage(String messageName, Map<String, Object> correlationKeys);
So in your case it is picking the wrong method and trying to put the string into the correlateMessage which takes in the map

Thanks @matt

So in expression mode we can not use correlateMessage method?

the following expression works properly in expression mode:


If you are using these methods

correlateMessage(String messageName)
correlateMessage(String messageName, String businessKey, Map<String, Object> correlationKeys, Map<String, Object> processVariables)

then I’d say its ok, so long as they don’t implement a new correlateMessage method with 1 or 4 parameters. So for me I’d go with that last expression for createMessageCorrelation as it seems less likely to cause an issue.

1 Like

thanks @matt