Hi everyone, I hope you can help me with this issue.
We are trying to correlate a message via a intermediate message throw event to a message start event in an event subprocess (see attached example). The message correlation seems to work, at least i don’t get a “can’t correlate message” Exception (which i get when i e.g. set a wrong message name) but somehow the tasks in the subprocess are not executed. Event worse: also the parent process instance is terminated afterwards.
When i look at the activity history, the last executed Task is the intermediate throw event.
Is there something wrong with this kind of construct or is that a bug ?
Here are some files to illustrate the problem (BPMN, Unittest, Delegate).
ProcessWithMessageEventSubprocess.bpmn (7.2 KB)
Test:
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.camunda.bpm.engine.ManagementService;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.repository.DeploymentBuilder;
import org.camunda.bpm.engine.runtime.Job;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class)
public class TestProzessMitEventSubprozess {
@Configuration
@Import(value={ProzessTestConfig.class})
static class Config{
@Bean
public SendMessageDelegate sendMessageDelegate(){
return new SendMessageDelegate();
}
}
@Autowired
private ProcessEngine engine;
@Before
public void setUp() {
deploy("ProcessWithMessageEventSubprocess.bpmn");
}
@Test
public void test(){
ProcessInstance processInstance = engine.getRuntimeService().startProcessInstanceByKey("processWithMessageEventSubprocess");
System.out.println("!!!!!!!!!!!!!! Task 1 !!!!!!!!!!!!!!");
printActiveJobs();
printActivityInstanceTree(processInstance);
printActivityHistory();
executeAsyncTask("task1");
System.out.println("!!!!!!!!!!!!!! Message !!!!!!!!!!!!!!");
printActiveJobs();
printActivityInstanceTree(processInstance);
printActivityHistory();
executeAsyncTask("messageToSubprocess");
System.out.println("!!!!!!!!!!!!!! Task im Subprozess !!!!!!!!!!!!!!");
printProcessInstances();
printActiveJobs();
printActivityInstanceTree(processInstance);
printActivityHistory();
executeAsyncTask("subprocessTask");
System.out.println("!!!!!!!!!!!!!! Task 2 !!!!!!!!!!!!!!");
printActiveJobs();
printActivityInstanceTree(processInstance);
printActivityHistory();
executeAsyncTask("task2");
assertThat(engine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstance.getId()).list().size(), is(0));
}
private void printProcessInstances() {
System.out.println("---------------- Process Instances ----------------");
System.out.println(engine.getRuntimeService().createProcessInstanceQuery().list());
System.out.println("----------------------------------------------------");
}
public void printActivityInstanceTree(ProcessInstance processInstance) {
System.out.println("---------------- Activity Instance Tree ----------------");
System.out.println(engine.getRuntimeService().getActivityInstance(processInstance.getId()));
System.out.println("----------------------------------------------------");
}
public void printActiveJobs() {
System.out.println("---------------- Pending Jobs ----------------");
engine.getManagementService().createJobQuery().active().list()
.stream()
.forEach(job -> System.out.println(job.toString()));
System.out.println("----------------------------------------------");
}
public void printActivityHistory() {
System.out.println("---------------- Activity History ----------------");
engine.getHistoryService().createHistoricActivityInstanceQuery().orderByHistoricActivityInstanceStartTime().desc().list()
.stream()
.forEach(activityInstance -> System.out.println(activityInstance.toString()));
System.out.println("--------------------------------------------------");
}
private void executeAsyncTask(String activityId){
ManagementService managementService = engine.getManagementService();
List<Job> jobs = managementService.createJobQuery().active().activityId(activityId).list();
assertThat(jobs.size(), is(1));
managementService.executeJob(jobs.get(0).getId());
}
private void deploy(String... resources) {
DeploymentBuilder deploymentBuilder = engine.getRepositoryService().createDeployment();
for (String resource: resources) {
deploymentBuilder.addClasspathResource(resource);
}
deploymentBuilder.deploy();
}
}
Delegate:
import org.camunda.bpm.engine.delegate.DelegateExecution;
public class SendMessageDelegate {
public void sendMessage(DelegateExecution execution, String messageName){
execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(messageName).processInstanceId(execution.getProcessInstanceId()).correlate();
}
}
This is the resulting sysout that is printed by the test:
!!!!!!!!!!!!!! Task 1 !!!!!!!!!!!!!!
---------------- Pending Jobs ----------------
MessageEntity[repeatnull, id=11, revision=1, duedate=null, lockOwner=null, lockExpirationTime=null, executionId=8, processInstanceId=8, isExclusive=true, retries=1, jobHandlerType=async-continuation, jobHandlerConfiguration=transition-create-scope, exceptionByteArray=null, exceptionByteArrayId=null, exceptionMessage=null, deploymentId=1]
----------------------------------------------
---------------- Activity Instance Tree ----------------
└── processWithMessageEventSubprocess:1:3=>8
└── transition to/from task1:8
----------------------------------------------------
---------------- Activity History ----------------
HistoricActivityInstanceEntity[activityId=StartEvent_1, activityName=null, activityType=startEvent, activityInstanceId=null, activityInstanceState=0, parentActivityInstanceId=8, calledProcessInstanceId=null, calledCaseInstanceId=null, taskId=null, taskAssignee=null, durationInMillis=2, startTime=Wed Aug 31 15:50:42 CEST 2016, endTime=Wed Aug 31 15:50:42 CEST 2016, eventType=null, executionId=8, processDefinitionId=processWithMessageEventSubprocess:1:3, processInstanceId=8]
--------------------------------------------------
!!!!!!!!!!!!!! Message !!!!!!!!!!!!!!
---------------- Pending Jobs ----------------
MessageEntity[repeatnull, id=13, revision=1, duedate=null, lockOwner=null, lockExpirationTime=null, executionId=8, processInstanceId=8, isExclusive=true, retries=1, jobHandlerType=async-continuation, jobHandlerConfiguration=transition-create-scope, exceptionByteArray=null, exceptionByteArrayId=null, exceptionMessage=null, deploymentId=1]
----------------------------------------------
---------------- Activity Instance Tree ----------------
└── processWithMessageEventSubprocess:1:3=>8
└── transition to/from messageToSubprocess:8
----------------------------------------------------
---------------- Activity History ----------------
HistoricActivityInstanceEntity[activityId=task1, activityName=Task 1, activityType=task, activityInstanceId=null, activityInstanceState=0, parentActivityInstanceId=8, calledProcessInstanceId=null, calledCaseInstanceId=null, taskId=null, taskAssignee=null, durationInMillis=0, startTime=Wed Aug 31 15:50:43 CEST 2016, endTime=Wed Aug 31 15:50:43 CEST 2016, eventType=null, executionId=8, processDefinitionId=processWithMessageEventSubprocess:1:3, processInstanceId=8]
HistoricActivityInstanceEntity[activityId=StartEvent_1, activityName=null, activityType=startEvent, activityInstanceId=null, activityInstanceState=0, parentActivityInstanceId=8, calledProcessInstanceId=null, calledCaseInstanceId=null, taskId=null, taskAssignee=null, durationInMillis=2, startTime=Wed Aug 31 15:50:42 CEST 2016, endTime=Wed Aug 31 15:50:42 CEST 2016, eventType=null, executionId=8, processDefinitionId=processWithMessageEventSubprocess:1:3, processInstanceId=8]
--------------------------------------------------
!!!!!!!!!!!!!! Task im Subprozess !!!!!!!!!!!!!!
---------------- Process Instances ----------------
[]
----------------------------------------------------
---------------- Pending Jobs ----------------
----------------------------------------------
---------------- Activity Instance Tree ----------------
null
----------------------------------------------------
---------------- Activity History ----------------
HistoricActivityInstanceEntity[activityId=messageToSubprocess, activityName=Message to Subprocess, activityType=intermediateMessageThrowEvent, activityInstanceId=null, activityInstanceState=2, parentActivityInstanceId=8, calledProcessInstanceId=null, calledCaseInstanceId=null, taskId=null, taskAssignee=null, durationInMillis=12, startTime=Wed Aug 31 15:50:43 CEST 2016, endTime=Wed Aug 31 15:50:43 CEST 2016, eventType=null, executionId=8, processDefinitionId=processWithMessageEventSubprocess:1:3, processInstanceId=8]
HistoricActivityInstanceEntity[activityId=task1, activityName=Task 1, activityType=task, activityInstanceId=null, activityInstanceState=0, parentActivityInstanceId=8, calledProcessInstanceId=null, calledCaseInstanceId=null, taskId=null, taskAssignee=null, durationInMillis=0, startTime=Wed Aug 31 15:50:43 CEST 2016, endTime=Wed Aug 31 15:50:43 CEST 2016, eventType=null, executionId=8, processDefinitionId=processWithMessageEventSubprocess:1:3, processInstanceId=8]
HistoricActivityInstanceEntity[activityId=StartEvent_1, activityName=null, activityType=startEvent, activityInstanceId=null, activityInstanceState=0, parentActivityInstanceId=8, calledProcessInstanceId=null, calledCaseInstanceId=null, taskId=null, taskAssignee=null, durationInMillis=2, startTime=Wed Aug 31 15:50:42 CEST 2016, endTime=Wed Aug 31 15:50:42 CEST 2016, eventType=null, executionId=8, processDefinitionId=processWithMessageEventSubprocess:1:3, processInstanceId=8]
Thanks in advance for your help,
Jan