Hi everyone!
I have a problem with signals in activiti. Please help me.
My case: i have two simple processes (p1 and p2)
p1: start -> catchSignal -> end
p2: start -> throwSignal (async) -> end
First, i start process p1. Second, i start process p2. They launched in separates java threads.
This is how it works in my case (based on RuntimeService events):
>>> [start_p1][ACTIVITY_STARTED]
>>> [start_p1][ACTIVITY_COMPLETED]
>>> [signal_catch_p1][ACTIVITY_STARTED]
>>> [start_p2][ACTIVITY_STARTED]
>>> [start_p2][ACTIVITY_COMPLETED]
>>> [signal_throw_p2][ACTIVITY_STARTED]
>>> [signal_catch_p1][ACTIVITY_SIGNALED]
>>> [signal_throw_p2][ACTIVITY_COMPLETED]
>>> [end_p2][ACTIVITY_STARTED]
>>> [end_p2][ACTIVITY_COMPLETED]
I can't understand, why process p1 not ended? Signal_catch_p1 was signaled... and nothing more. I expected signal_catch_p1 to be completed and process go to end.
Java code:
public void test() {
String bpmnDbPath = "E:\\activiti-db;DB_CLOSE_DELAY=1000";
ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
cfg = cfg.setJdbcDriver("org.h2.Driver").setJdbcUrl("jdbc:h2:" + bpmnDbPath).setJdbcUsername("sa")
.setJdbcPassword("").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
ManagedAsyncJobExecutor jobExecutor = new ManagedAsyncJobExecutor();
jobExecutor.setAutoActivate(true);
jobExecutor.setCorePoolSize(3);
jobExecutor.setMaxPoolSize(20);
cfg.setAsyncExecutor(jobExecutor);
cfg.setAsyncExecutorActivate(true);
ProcessEngine processEngine = cfg.buildProcessEngine();
processEngine.getRuntimeService().addEventListener(new ActivitiEventListener() {
@Override
public void onEvent(ActivitiEvent activitiEvent) {
if (activitiEvent instanceof ActivitiActivityEventImpl) {
ActivitiActivityEventImpl aaeImpl = (ActivitiActivityEventImpl) activitiEvent;
String activitiId = aaeImpl.getActivityId();
String type = activitiEvent.getType().toString();
System.out.println(String.format(">>> [%s][%s]", activitiId, type));
}
}
@Override
public boolean isFailOnException() {
return true;
}
});
String p1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:activiti=\"http://activiti.org/bpmn\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"http://www.omg.org/spec/DD/20100524/DI\" typeLanguage=\"http://www.w3.org/2001/XMLSchema\" expressionLanguage=\"http://www.w3.org/1999/XPath\" targetNamespace=\"http://www.activiti.org/test\">\n" +
" <signal id=\"UnknownSignal\" name=\"UnknownSignal\"></signal>\n" +
" <process id=\"p1\" isExecutable=\"true\">\n" +
" <endEvent id=\"end_p1\"></endEvent>\n" +
" <startEvent id=\"start_p1\"></startEvent>\n" +
" <intermediateCatchEvent id=\"signal_catch_p1\">\n" +
" <signalEventDefinition signalRef=\"UnknownSignal\"></signalEventDefinition>\n" +
" </intermediateCatchEvent>\n" +
" <sequenceFlow sourceRef=\"start_p1\" targetRef=\"signal_catch_p1\"></sequenceFlow>\n" +
" <sequenceFlow sourceRef=\"signal_catch_p1\" targetRef=\"end_p1\"></sequenceFlow>\n" +
" </process>\n" +
"</definitions>";
String p2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<definitions xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:activiti=\"http://activiti.org/bpmn\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:omgdc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:omgdi=\"http://www.omg.org/spec/DD/20100524/DI\" typeLanguage=\"http://www.w3.org/2001/XMLSchema\" expressionLanguage=\"http://www.w3.org/1999/XPath\" targetNamespace=\"http://www.activiti.org/test\">\n" +
" <signal id=\"UnknownSignal\" name=\"UnknownSignal\"></signal>\n" +
" <process id=\"p2\" isExecutable=\"true\">\n" +
" <endEvent id=\"end_p2\"></endEvent>\n" +
" <startEvent id=\"start_p2\"></startEvent>\n" +
" <intermediateThrowEvent id=\"signal_throw_p2\">\n" +
" <signalEventDefinition signalRef=\"UnknownSignal\" activiti:async=\"true\"></signalEventDefinition>\n" +
" </intermediateThrowEvent>\n" +
" <sequenceFlow sourceRef=\"start_p2\" targetRef=\"signal_throw_p2\"></sequenceFlow>\n" +
" <sequenceFlow sourceRef=\"signal_throw_p2\" targetRef=\"end_p2\"></sequenceFlow>\n" +
" </process>\n" +
"</definitions>";
deployAndStartProcess(processEngine, p1, "p1");
deployAndStartProcess(processEngine, p2, "p2");
}
private void deployAndStartProcess(ProcessEngine processEngine, String bpmnProcess, String processId) {
try {
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder db = repositoryService.createDeployment();
String deploymentId = processId + ".bpmn20.xml";
db.addString(deploymentId, bpmnProcess).deploy();
Runnable r = () -> runtimeService.startProcessInstanceByKey(processId);
(new Thread(r)).start();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
Did you checked the event logs at this table in activiti act_evt_log.Because when i see the similar application running using activiti app(not from the java code) it is able to end the process p1 in my case.below is the event logs from my activiti databse. also please find the attachment of my APP.
25 | VARIABLE_CREATED | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:05.095 | 1 | ... | 1 | ||||
26 | HISTORIC_PROCESS_INSTANCE_CREATED | signal_catch_process:1:25007 | 25022 | 2018-07-31 12:16:05.097 | 1 | ... | 1 | |||||
27 | HISTORIC_ACTIVITY_INSTANCE_CREATED | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:05.104 | 1 | ... | 1 | ||||
28 | HISTORIC_ACTIVITY_INSTANCE_ENDED | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:05.109 | 1 | ... | 1 | ||||
29 | SEQUENCEFLOW_TAKEN | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:05.101 | 1 | ... | 1 | ||||
30 | HISTORIC_ACTIVITY_INSTANCE_CREATED | signal_catch_process:1:25007 | 25022 | 25026 | 2018-07-31 12:16:05.110 | 1 | ... | 1 | ||||
31 | VARIABLE_CREATED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.121 | 1 | ... | 1 | ||||
32 | HISTORIC_PROCESS_INSTANCE_CREATED | signal_throwing_process:1:25006 | 25029 | 2018-07-31 12:16:45.121 | 1 | ... | 1 | |||||
33 | HISTORIC_ACTIVITY_INSTANCE_CREATED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.121 | 1 | ... | 1 | ||||
34 | HISTORIC_ACTIVITY_INSTANCE_ENDED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.136 | 1 | ... | 1 | ||||
35 | SEQUENCEFLOW_TAKEN | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.121 | 1 | ... | 1 | ||||
36 | HISTORIC_ACTIVITY_INSTANCE_CREATED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.136 | 1 | ... | 1 | ||||
37 | HISTORIC_ACTIVITY_INSTANCE_ENDED | signal_catch_process:1:25007 | 25022 | 25026 | 2018-07-31 12:16:45.155 | 1 | ... | 1 | ||||
38 | SEQUENCEFLOW_TAKEN | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:45.136 | 1 | ... | 1 | ||||
39 | HISTORIC_ACTIVITY_INSTANCE_CREATED | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:45.157 | 1 | ... | 1 | ||||
40 | HISTORIC_ACTIVITY_INSTANCE_ENDED | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:45.165 | 1 | ... | 1 | ||||
41 | HISTORIC_PROCESS_INSTANCE_ENDED | signal_catch_process:1:25007 | 25022 | 2018-07-31 12:16:45.159 | 1 | ... | 1 | |||||
42 | VARIABLE_DELETED | signal_catch_process:1:25007 | 25022 | 25022 | 2018-07-31 12:16:45.162 | 1 | ... | 1 | ||||
43 | HISTORIC_ACTIVITY_INSTANCE_ENDED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.167 | 1 | ... | 1 | ||||
44 | SEQUENCEFLOW_TAKEN | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.159 | 1 | ... | 1 | ||||
45 | HISTORIC_ACTIVITY_INSTANCE_CREATED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.175 | 1 | ... | 1 | ||||
46 | HISTORIC_ACTIVITY_INSTANCE_ENDED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.174 | 1 | ... | 1 | ||||
47 | HISTORIC_PROCESS_INSTANCE_ENDED | signal_throwing_process:1:25006 | 25029 | 2018-07-31 12:16:45.176 | 1 | ... | 1 | |||||
48 | VARIABLE_DELETED | signal_throwing_process:1:25006 | 25029 | 25029 | 2018-07-31 12:16:45.179 | 1 | ... | 1 |
Forgot to attach the app......
tabrez khan
Thank you for answer.
I looked at your app. But it contains one important difference from my case: you use IntermediateThrowSignal in sync mode. I want use this in async mode.
I see you are using Async Intermediate throwing event. I guess you can see some of the test cases written in activiti-engine which you can find helpful......
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.