Need help with Message Correlation

Hi all,

I have a case where I have to create two processes, p1 that can have multiple related p2 processInstances,

  • The p2 processes have a reference to p1 processes using the variable called “referencePID”.
  • In p1 process diagram there’s a listener script which runs when task:Step1 gets completed.
  • Meanwhile the user can work upon p2’s task which listens to a non interrupting message.
  • The task for the p2 will be in active state till a variable is set called “referenceTaskCompleted”.
  • As soon as the script runs, the code correlates all processes having processInstanceVariableEquals(“referencePID”, execution.getProcessInstanceId()) and then sets the variable “referenceTaskCompleted” to mark it as complete.

When I try to send the same data with /message Rest API, things works correctly. But if I try with the functions The process Instances of p2 automatically gets Completed without tasks coming up for the second taskDefinition in p2, also there are no Exceptions in the logs.

where am I doing things wrong?

Code for listener script:

execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation("Message_3e2312f").processInstanceVariableEquals("referencePID",execution.getProcessInstanceId()).setVariable("referenceTaskCompleted", true).correlateAll();

Message Name: Message_3e2312f

Request body for /message

{
  "messageName" : "Message_3e2312f",
  "processInstanceId" : "b2943d00-9709-11e9-bc7d-0242ac160005",
  "processVariables" : {
    "referenceTaskCompleted" : {"value" : true, "type": "Boolean"}
  },
  "resultEnabled" : true,
  "variablesInResultEnabled" : true
}

diagram_7.bpmn (7.4 KB)

Hi @vermauv,

I see a problems with your process:

  • in the start listener you set referenceTaskCompleted but
  • in the condition, you check for #{parentTaskCompleted == true}, please try to align your variable’s name.

Hi @Yana,
I’ve fixed the diagram,
Still my concern remains the same i.e. message variable set from p1 doesn’t get correlate to p2.

Hello @vermauv,

I’m not really sure what your trying to accomplish with the process your demonstrating. Possibly more info on the use case can allow me to provide a more specific answer to your question.

But in the meantime I will say this looks to be an anti-pattern your applying. There is no guarantee Processes2 will be at Step 1 when Process 1 attempts to correlate the message. This seems like the appropriate use case for a Signal Event not a Message Event.

If you want to apply the Message Event pattern correctly you should use a Message Listener/Handler that lives out side of the process context. The listener can live inside the application context (or outside) but not in the process execution context.

Hope this helps.
Cheers

Hi @plungu,

The actual use case is to complete all related processes (>1) for a process when it gets completed, till then they have to be in active state, I can’t use signal event as it broadcasts to all process listening to a common signal name, while I need something that completes only the related ones.

Hi @vermauv,

When script has been run, do you have any active instances of Process2? In case you have, Could you provide us with a view of the process variables for the instances from the cockpit app…

To make the signal unique to the correct workflow instances you can use an expression in the signal name.

You still have the same problem though. There’s a chance process2 has not reached the catch event when the message/signal correlation is sent. You still need to be sure all the required process2 instances have reached the catch event.

Since you can correlate using the REST api this further suggests a timing issue. Try to start all the process2 instances than start process1. Do you still have the same issue?

1 Like

Hi @plungu, Its solved now. Thanks anyway :slight_smile: