Receive Message event in race condition

Hey, I have particular requirement. There will be 2 processes say P1 & P2.
P1 will publish a Message event which will be listened by P2 at intermediate step.
If P2 hasn’t reached wait state to receive Message event while P1 has completed processing and ready to publish event.

P2 has to complete certain steps before it’s ready to listen to Message event.

How can I solve this scenario in order that Message event is published by P1 and it has to be consumed when P2 reaches wait state?

Please help.
Thank you.

Hi,

In P2 you coukd have a non interrupting message driven subprocess which sets a condition to true, ie P1 message received. If this is true, no need to wait for P1 message to arrive…

This is one pattern, other plugins exist to store messages for delivery…

Regards

Rob

Thank you quick reply Rob.

Could you please help me understand with a sample BPM.

1 Like

This works. Thank you so much!

Hello,

Follow up on same,

As per the requirements there are possibilities that multiple instances of P2 can be running, as P2 is a sub process.
I would like all P2 running instances to receive the event published by P1.

When I tried as per the diagram above, getting error as there are multiple correlations matching.

Please let me know a solution for same.

Thank you.

If you like you can try to correlate on the business key as well as unique local variables.

I am trying the same -
runtimeService.createMessageCorrelation(“topic”).processInstanceBusinessKey(execution.getProcessBusinessKey()).correlateWithResult()
this throws error when multiple instances of P2 are running.
Please correct if anything missing.

You have two ways of finding a waiting instance.

  1. The topic name, in your case topic
  2. the business key which is apparently the same as the parent key

To this method you can also a variable that you expect will exist for a specific instance of the process. without more information about your process i can’t really make a suggestion.

Hi Nial,

Thank you.
Actually I want to understand can multiple processes receive same message event?
In my case when 2 instances of P2 are running, while P1 tries to publish event I am getting an error stating cannot correlate as multiple instances running. I can look to share the exact error message.

Alright, in that case you just need to add .corrolateAll() to the end of your method instead of .correlateWithResult()

1 Like

Thank you so much!