cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger a Sub flow using "Signal Event" which is getting generated in Parent Flow ?

sushant
Champ in-the-making
Champ in-the-making

Issue - At step 3, Subflow is not getting called in spite of configuration. Please provide any pointers. I do not want to call this child flow from  parent flow like below :

1 ACCEPTED ANSWER

gdharley
Elite Collaborator
Elite Collaborator

Hi Sushant, I tried what I had proposed and found it didnt work, so I checked the Activiti defect list.

Seems this is a known (unresolved) issue:

Issue Navigator - ACTIVITI-286 - Activiti: Event sub process not triggered with start signal thrown 

I suggest you vote up this issue so we can get it resolved.

Sorry,

Greg

View answer in original post

22 REPLIES 22

thuynh
Star Contributor
Star Contributor

Hi Sushant,

Hmm ok. I'm not sure. I just tried firing even from a TaskListener and it worked for me as well. Here's my task listener class.

public class MyTaskCreateListener implements TaskListener {

Logger logger = Logger.getLogger(MyTaskCreateListener.class);

public void notify(DelegateTask delegateTask) {
// Custom logic goes here
logger.info("User task is created.");
logger.info("Listener executed.");

DelegateExecution execution = delegateTask.getExecution();
RuntimeService runtimeService = execution.getEngineServices().getRuntimeService();
runtimeService.signalEventReceived("EMAIL_SUPPORT_SIGNAL");
}
}

And here is the unit test log

03:43:19,694 [main] INFO org.activiti.signal.SignalUnitTest - ------------------------- START SIGNAL CATCH PROCESS -------------------------
03:43:19,761 [main] INFO org.activiti.signal.SignalUnitTest - Execution counts: 2
03:43:19,771 [main] INFO org.activiti.signal.SignalUnitTest - Execution: null - 18
03:43:19,772 [main] INFO org.activiti.signal.SignalUnitTest - Execution: null - 20
03:43:24,773 [main] INFO org.activiti.signal.SignalUnitTest - ------------------------- START SIGNAL TEST PROCESS -------------------------
03:43:24,789 [main] INFO org.activiti.signal.MyTaskCreateListener - User task is created.
03:43:24,789 [main] INFO org.activiti.signal.MyTaskCreateListener - Listener executed.
03:43:24,806 [main] INFO org.activiti.signal.SendErrorService - SendErrorService executed. Process: signalStartProcess:1:16
03:43:24,823 [main] INFO org.activiti.signal.SendErrorService - SendErrorService executed. Process: signalCatchProcess:1:15
03:43:24,855 [main] INFO org.activiti.signal.SignalUnitTest - Process instance id: 23
03:43:24,870 [main] INFO org.activiti.signal.SignalUnitTest - Open task : 27 - Review Create Subscription Failure / assigned to: null
03:43:29,870 [main] INFO org.activiti.signal.SignalUnitTest - ------------------------- CHECK SIGNAL CATCH PROCESS -------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 19.549 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.353s
[INFO] Finished at: Wed Jan 25 15:43:35 ICT 2017
[INFO] Final Memory: 8M/153M
[INFO] ------------------------------------------------------------------------

Let me know if this still not matching your use case.

Thanks

Thong Huynh

sushant
Champ in-the-making
Champ in-the-making

Hi Thong,

Reason why your works is because:

1. In your subflow, usual "Start Event" is used followed by "Intermediate Catch Event".

2. Subflow is explicitly getting called in the unit test class.

      ProcessInstance processInstance2 = activitiRule.getRuntimeService().startProcessInstanceByKey("signalCatchProcess");

So, in gist this is like calling a subflow like below(my un-preferred option of original thread)

What I want is :

My subflow should have "Start Signal Event" instead of #2 above. Which would be starting the subflow automatically when it sees an event getting fired from Task listener, as illustrated below

Hope, I am clear.

thuynh
Star Contributor
Star Contributor

thuynh
Star Contributor
Star Contributor

Hi Sushant Kumar ,

1. In your subflow, usual "Start Event" is used followed by "Intermediate Catch Event".

This is just one scenario. Please look at the other one as well, signal-start-process.bpmn. This one has a signal start event. In my unit test, you can see both scenarios work.

 

2. Subflow is explicitly getting called in the unit test class.

      ProcessInstance processInstance2 = activitiRule.getRuntimeService().startProcessInstanceByKey("signalCatchProcess");

Again, this is for the 1st scenario where I want to test the intermediate signal catch event. Have a look at signal-start-process.bpmn

I have attached the unit test project.

Please look at signal-start-process.bpmn, you can disable the other one 'signal-catch-process' to be less confused about it.

If you still see problem, please upload a unit test. 

Thank you,

Thong Huynh

sushant
Champ in-the-making
Champ in-the-making

Hi Thong Huynh,

It works with Junits - where I am starting the main flow using start process instance - i.e signalTaskListenerProcess. So, may be :

1. It does not work, if i start using REST call

2. I am using version activiti-engine-5.19.0.3 version.

Attaching my test case, Please use REST call to start as below

POST /activiti-app/api/runtime/process-instances HTTP/1.1
Host: localhost:8080
Content-Type: application/json
Authorization: Basic gskkanaoa10177161==
Cache-Control: no-cache
Postman-Token: 969177c4-b779-386a-29f4-708e9e93bd0f

{
"processDefinitionId":"Sushant-Signal-Throw-Process:4:2425624",
"businessKey":"Sushant-Signal-Throw-Process"

}

Link to testcase - Test-Signal-App.zip 

Listener class

package com.pb.saase2e.cs.workflow.task.listener;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UserTaskListener implements TaskListener {

private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(UserTaskListener.class);

@Override
public void notify(DelegateTask delegateTask) {

RuntimeService runtimeService = delegateTask.getExecution().getEngineServices().getRuntimeService();

delegateTask.getExecution().setVariable("TaskId", delegateTask.getId());
delegateTask.getExecution().setVariable("TaskName", delegateTask.getName());

runtimeService.signalEventReceived("EMAIL_SUPPORT_SIGNAL");
logger.info("Sent signal event:{} for taskId:{} and taskName:{}", "EMAIL_SUPPORT_SIGNAL", delegateTask.getId(),
delegateTask.getName());

}
}

Destryon
Champ in-the-making
Champ in-the-making

Hi Thuynh,

I was trying to create a trigger in my main flow that will be triggering sub flows. Now i am confused whether we can use timer event or sub process to achieve it?  

sushant
Champ in-the-making
Champ in-the-making

Any idea, if this is fixed in 5.x version ?

gdharley
Elite Collaborator
Elite Collaborator

This remains a defect and doesnt appear to be fixed in the latest 5.x engine release.

In addition, it appears to be an issue in the version 6 Beta release as well.

gdharley
Elite Collaborator
Elite Collaborator

Sushant,
I opened up your package and I think we will need you to attach the TaskListener since this is what throws the signal.

com.pb.saase2e.cs.workflow.task.listener.UserTaskListener

It appears the key piece was missing from the application package.

Thanks,
Greg

sushant
Champ in-the-making
Champ in-the-making

Edited my post to include the listener java class. Here it is again

package com.pb.saase2e.cs.workflow.task.listener;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UserTaskListener implements TaskListener {

private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(UserTaskListener.class);

@Override
public void notify(DelegateTask delegateTask) {

RuntimeService runtimeService = delegateTask.getExecution().getEngineServices().getRuntimeService();

delegateTask.getExecution().setVariable("TaskId", delegateTask.getId());
delegateTask.getExecution().setVariable("TaskName", delegateTask.getName());

runtimeService.signalEventReceived("EMAIL_SUPPORT_SIGNAL");
logger.info("Sent signal event:{} for taskId:{} and taskName:{}", "EMAIL_SUPPORT_SIGNAL", delegateTask.getId(),
delegateTask.getName());

}
}