Communication between different BPM processes with Send and Receive task (message event)

Hello,

Is it possible to use Send and Receive tasks in the following way?

There are 2 BPMS.
I start 1 bpm process and reach Receive Task, now I am waiting.
I also start the other bpm process, it reaches a Send Task and sends an event.
The first bpm process catches this event with the Receive task and continues.

limitations:

If I got hundreds of running processes I only want to have a trigger between “son and father”,
I want a 1 to 1 relation and not 1: all.

Is such a thing possible with those tasks?
And if not is there anything else I should consider using?

Thank you in advance!

Hi @Ivgi,

In BPMN a message has always a 1:1 relation. So using receive and send message is the way to go. You just have to make sure that the message can correlate. So it needs to have a unique identifier like for example the process instance id or the business key.

I hope that helps Cheers
Nele

2 Likes

Thank you for the response!

If I understand correctly,
I can implement the “Send Task” as an external task and then in the micro service logic of that external task I will send http request to Camunda API https://docs.camunda.org/manual/latest/reference/rest/message/post-message/

With the messageName of the “receive task” and also a unique identifier like a processId.

The problem is that I dont have the processId of the parent BPM process.
I also can not use unique business key because it is already being used for a different purpose.

Is there any other way to create the 1:1 relation between them?

Can I use a process variable as the identifier?
If I am not mistake I can then add it to the correlationKeys and make the 1:1 match with that?

For example:
When I start a new process for the first bpm I want to add a process variable named “messageId” with a unique Identifier.
I will then send this variable to the second process as well.
At the end of the second process I will add “end event message” as another external task.
The logic behind this end event will be responsible for sending the request to the Camunda API with the message name and the correlation key “messageId”.
Which is going to trigger the first bpm process with 1:1 relation.

Hi @Ivgi,

Exactly… you can use correlationKeys the way you described to make sure that 1:1 relation is constructed.
You can even use multiple process variables as correlationKeys.

2 Likes

Hello,

here’s a simple delegate I have made that sends message to another process. You need to define Either ‘correlationKeys’ Local variable in the delegate input mappings or use a business key to correlate.

Sample correlation client and correlation target process also attached.

public class SendMessageDelegate implements JavaDelegate {

    

    private final Logger LOGGER = Logger.getLogger(SendMessageDelegate.class.getName());

    @Override

    public void execute(DelegateExecution execution) throws Exception {

        // TODO Auto-generated method stub

        LOGGER.finer("SendMessageDelegate started");        

        String messageName = (String) execution.getVariableLocal("messageName");

        execution.removeVariableLocal("messageName");

        LOGGER.finer("Will send Message named " + messageName); 

                

        // Are correlation keys present?

        if(execution.hasVariable("correlationKeys")) {

            // Use correlation keys

            LOGGER.finer("Using Correlation keys ");

            //First lets get the Correlation keys

            TreeMap<String,Object> corrKeyMap = (TreeMap<String,Object>) execution.getVariableLocal("correlationKeys");

            //then we remove them from variables

            execution.removeVariable("correlationKeys");

            execution.getProcessEngineServices().getRuntimeService().correlateMessage(messageName, corrKeyMap, execution.getVariablesLocal());

        }else {

        

            // Is Business key present?

            String bKey = execution.getBusinessKey();

        

            if (bKey != null && bKey.isEmpty() == false) {

                //Send the message with variables

                LOGGER.finer("Using Business key " + bKey) ;    

                execution.getProcessEngineServices().getRuntimeService().correlateMessage(messageName, bKey, execution.getVariablesLocal());            

            }else {

                LOGGER.severe("No business key or correlation keys present");

                throw new Exception("Unsupported request: Must use business key or correlation keys");      

            }

        }

    

        LOGGER.finer("SendMessageDelegate ended");

    }

}

correlationClient.bpmn (4.1 KB) CorrelationTarget.bpmn (4.5 KB)

1 Like

Hi @JussiL
Thanks for posting your solution, i edited your post to make the code easier to read.

No problem.

For some reason, I could not upload the java file, so I had to copy paste it.

1 Like