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

cancel
Showing results for 
Search instead for 
Did you mean: 
sushant
Member II

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

Jump to solution

I can do a screenshare and show you. BTW, on the User Task , did the event generated after you actioned the user task ? if yes, then I fear that is not the use case. I see above in logs, the task getting assigned.

Here are the steps:

1. Create a flow which generated the user task.

2. Do not action the User task i.e keep it open.

3. Configure Java User Task Listener(on Create event of task) on this which generates the event.

4. Now, configure the same event on a subflow as start signal event.

Now, if you run, the subflow at #4 does not get invoked. 

thuynh
Established Member II

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

Jump to solution

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

gdharley
Intermediate

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

Jump to solution

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.

sushant
Member II

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

Jump to solution

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
Established Member II

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

Jump to solution

Hi 

thuynh
Established Member II

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

Jump to solution

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
Member II

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

Jump to solution

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());

}
}

gdharley
Intermediate

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

Jump to solution

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
Member II

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

Jump to solution

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());

}
}

gdharley
Intermediate

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

Jump to solution

Hey Sushant,

I am still trying to work out why the Signal is not being picked up.

But since you are calling the signal task from a Listener, I found a work around.

Rather than using a signal start event. Just use a regular start event.

Then, instead of sending the signal, simply start the sub process from the runtimeService using startProcessInstanceByKeyAndTenantId().

I have attached an updated project with the work around implemented.
Agreed, I dont like it and we need to work out why signals are not working in this scenario, but it shoudl get you moving.

Greg

bp3‌