Hi,
I am working on a process in my organization. Due to confidentiality reason I cannot disclose all the details, but here is what i am looking for implementing. A request will come to our camunda process from external system (using REST API). The process (top process in the diagram below) will check if a process already exists that has process variable with same value as the one received in request from external system.
If no, then “throw a signal event” to “Start” a new process (highlighted by red color), else if yes, then “throw a signal event” to “Resume” an existing process with updated variables (highlighted by blue color).
This design works when deployed in Camunda 7 server and tested with Postman requests. However, when i try to simulate the same in JUnit, the intermediate catch event in the 2nd process (below part of the diagram) does not move ahead in 2nd scenario.
Could you please show how you are trying to test this with JUnit.
And one other thing.
Signal events are like a broadcast, that is sent to every listening process instance.
In your case a message event would make more sense, as that would be correlated against one process instance and could also start one.
At runtime, we can have multiple process instances (bottom one from the diagram) running, and the running instances are waiting for its own signal (dynamic value using #{xxxUniqueIdentifier}). For e.g. lets say there are 3 processing running each one waiting at the intermediate catch event signal
P1 → xxxUniqueIdentifier = 123
P2 → xxxUniqueIdentifier = 456
P3 → xxxUniqueIdentifier = 007
Now, if a new request comes to resume the bottom process, … say only P2… then top process will throw a signal event with same xxxUniqueIdentifier = 456 at runtime. Since this is a broadcast it will be a signal for all bottom processes. However, only the process which is waiting to catch the signal 456 will resume and the token will move forward, and the other P1 and P3 will continue to wait until they get their signal.
As you can see, this kind of communication between two processes can be achieved logically at runtime using signals, and hence we have used the signal throw and catch approach. Also, we want to pass the variables from the top process to the bottom process.
Please note that this is working perfectly fine when deployed in camunda engine. I have checked the audit log and process instance history in Cockpit to understand the flow of token, and it is working as expected.
However, as a part of code coverage, I have to now implement JUnit, but the same cannot be achieved in JUnit, the token does not move forward from the intermediate catch signal event after signal event has been thrown.
Due to security policy of our company, it is difficult to share code as it is, but let me remove the confidential parts and try to share the JUnit which will describe the basic approach how I am verifying the flow in the next post.
This does not scale well.
Using a message event allows you to send a message “Resume Processing” directly to P1, including any additional / update variables, and is more in line with the BPMN standard.
If you think of it in terms of “Human Workers” your message would look more like:
To: Process1 Worker
Subject: Resume Work
Details: Variable1 updated to This, Variale2 update to That
The overall message format would be the same all the time, just the specified destination and details would change when you want to update P2 or P3
A Signal would look more like:
To: All Employees
Subject: ObfuscatedCodeNumber123
Using messages rather than signals also improves your test cases, since you know in advance what the process IDs and messages would look like.
Still I think that the message event would be better suited for this purpose, as it resembles more your use case.
You want to directly address one process and not multiple, as would be the case for a broadcast.
And your message event could have one business related name and you could correlate by some variable value (e.g. uniqueIdentifier=456).
But can messages take dynamic values … like it has been done for signal ? Also, can i pass the process variables in case of message based communication ?
The message name is defined in the model, so it would be fixed.
But the dynamic comes from the correlation keys.
The RuntimeService provides a method correlateMessage, which you can use.
There you can define your correlation keys (which would e.g. be process variables) and you can also pass process variables to the process instance.
If there is no running process instance with those correlation keys and you have a message start event, that reacts on the same message name, a new process instance will be started.
Many thanks @rohwerj and apologies for late reply. At the moment, due to lower priority this development has been paused at the moment, however once we resume again, I shall try the approach you have suggested and will provide the updates here.
But many many thanks for your support and help. Appreciate it.