A question about communication between processes via bpmn message

1,586 views
Skip to first unread message

Stefan Schulz

unread,
Dec 26, 2013, 3:39:47 PM12/26/13
to camunda-...@googlegroups.com
Hello.

A have a question about starting a process instance with a message start event invoked from a task in another process. Please have a look at my model:


My first thought was that executing the task 'Trigger Receiver Process' in the sender process would (without any scripting or writing additional java code) start an instance of the receiver process. This is obviously not the case, as testing the process in the camunda engine showed me. Im not excepting a technically detailed answer here, but a hint for the right direction would be very nice. Am i right if i suppose that i have to start the receiver process 'manually', which means something like writing a java delegate attached to the 'Trigger Receiver Process' task in the sender process, get me a reference for the process engine in there and then do something like runtimeService.startProcessInstanceByMessage() ?

Thanks a lot,
Stefan

webcyberrob

unread,
Dec 26, 2013, 7:43:11 PM12/26/13
to camunda-...@googlegroups.com
Hi Stefan,

Looking at your process model, I would typically have a user task to interact with the user followed by a send message task such that the send message task is explicit. Now in the Camunda engine, theres no real difference between send message task an service task, each requires a 'handler' to perform some logic, so yes you could get a reference to the runtime object and cal the appropriate API...

webcyberrob

unread,
Dec 27, 2013, 1:13:15 AM12/27/13
to camunda-...@googlegroups.com
Stefan,

very simple example as per below. Note I used scrip tasks again just so the share file is a self contained process. Hopefully the groovy script gives you the idea...Note in a more real world example, I would expect correlation to be based on business key or process attributes. In this example I just use basic message name based correlation.

http://camunda.org/share/#/process/961e280f-47a2-4fe5-ace6-7b0d9b067137

regards

Rob


On Friday, December 27, 2013 7:39:47 AM UTC+11, Stefan Schulz wrote:

Stefan Schulz

unread,
Dec 27, 2013, 4:43:29 AM12/27/13
to camunda-...@googlegroups.com
Hi, Rob.

Im very glad...exactly what i was looking for. Thank you very much. I hope that one day i can do something for you, too.

Greetings,
Stefan

14ya...@gmail.com

unread,
Aug 19, 2014, 1:34:49 PM8/19/14
to camunda-...@googlegroups.com
Hi Rob,

Many thanks for your simple example. With you help I was able to init a process using the method "startProcessInstanceByMessage". I was not able to use the BpmPlatforme class as it return null so I use the execution variable. My second process starts as expected and go one without any Issue. But then when I want to informe my master process he dont receive the message and don't continue. I use the methode "createStandaloneInMemProcessEngineConfiguration" to configure my process engine. Could this be the issue that it is not possible to send a message to an StandAlone process. I'm not very familar with a BPMN engine so maybe it is a silly question. But I'm going crazy I have test several methode but not one relaunch the master process.

Below the sniped of my code to start the process.

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RuntimeService;

//get the processEngine of the current execution
ProcessEngine processEngine = execution.getProcessEngineServices();

execution.setVariable("callerProcessDefinitionId", execution.getProcessDefinitionId());
//send Process by message passing all arguments
processEngine.getRuntimeService().startProcessInstanceByMessage("checkIsolation",execution.getVariables());

thorben....@camunda.com

unread,
Aug 20, 2014, 3:58:59 AM8/20/14
to camunda-...@googlegroups.com, 14ya...@gmail.com
Hi,

could you please provide the process models of the "master process" and the process that sends the message or a simplified version of those that reproduces the problem? Ideally, you could use the unit test template that you can find here: https://github.com/camunda/camunda-engine-unittest

Best regards,
Thorben

14ya...@gmail.com

unread,
Aug 20, 2014, 4:58:56 AM8/20/14
to camunda-...@googlegroups.com, 14ya...@gmail.com
Hi Thorben,
Many thanks for your quick feedback.

I have published a git repository with my issue. you can find it under https://github.com/14yannick/camuda-interprocess

Many thanks for your help and best regards
Yannick

thorben....@camunda.com

unread,
Aug 20, 2014, 7:27:35 AM8/20/14
to camunda-...@googlegroups.com, 14ya...@gmail.com
Hi Yannick,

There are some issues with your processes:

1. Master > Script Task Launch Process: Using startProcessInstanceByMessage() synchronously starts a process instance, so Slave is instantiated and executed during the runtime of this task. However, Master does no wait for the signal event yet, so it cannot receive the signal issued from slave. To solve this issue, you have to make sure that Master expects the signal when it is sent.
One way to achieve this, is to use asynchronous continuations, so that the Master task only creates the process instance but process execution is done asynchronously (i.e. make the start event of Slave asynchronous). Then, Master can immediately proceed to the receive event. For this to work, you will have to use the JobExecutor, cf. [1]

2. Please be aware that signal events are always broadcast, so if you had two instances of Master, both would receive the signal sent by a single slave. If this is not your desired behavior, you could use message events instead.

3. Instead of using script tasks to start the process by message, the call activity might also be worth a look, cf [2]

Best regards,
Thorben

[1] http://docs.camunda.org/latest/guides/user-guide/#process-engine-the-job-executor
[2] http://docs.camunda.org/latest/api-references/bpmn20/#subprocesses-call-activity

14ya...@gmail.com

unread,
Aug 20, 2014, 11:37:07 AM8/20/14
to camunda-...@googlegroups.com, 14ya...@gmail.com
Hi Thorben,

Many thanks for your input. I now got the point regarding that my script activity was a "blocking" event.

Thank you for direct me to the subprocess-call-activity because it fulfil exactly what i'm looking for. My target is to use some "helper" process in multiple main processes.

Best Regards
Yannick

14ya...@gmail.com

unread,
Aug 20, 2014, 11:38:58 AM8/20/14
to camunda-...@googlegroups.com, 14ya...@gmail.com
And I forgot to mention that I have updated the git using the call activity https://github.com/14yannick/camuda-interprocess
Reply all
Reply to author
Forward
0 new messages