Correlate message for receive task with same key for Multiple process instance


In here the service task is hitting an API until the desired response is found, then it correlates the “JobCompleted” message to the receive task. The process then gets forwarded towards sending the mail.

The issue is when two instances are fired to the process definition, both the instances after getting successful response from the API correlate to the same key of message for receive task, and that throws an exception.

I have attached the cockpit and eclipse code of service task.
The console containing error also, till the time the timer is running there is no error but as soon as message correlation comes in picture it gets conflicted when at a time 2 or more instances are running. Note: When there is only one instance running the process flow is perfect.


If you want to correlate multiple messages, you need to call MessageCorrelationBuilder.correlateAll()

No, I want to correlate only 1 message and there is only 1 receive task. But when multiple instances of the process are created that 1 message correlation also gets conflicted. Please see the bpmn diagram in the cockpit and the error screen.
When multiple instances after completing the timer, trigger the receive event with message correlation with the same key there is an issue.

you can try using the localCorrelationKeys param as part of your request. If you create a local variable for each local scope you can correlate to it.
https://docs.camunda.org/manual/7.10/reference/rest/message/post-message/

This solution is through a rest call, please suggest me a way to do from within my “check status” service task whose code also I have provided.
Rest call is not preferred because “/message” call is separate from the “/start” call.