How to signal another process?

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

How to signal another process?

Hello dear all,

Basically i am struggling with understanding how to send and receive signals (messages) between different processes. 

Could you please help me to design or give me a hints how to create in Eclipse Activiti Designer something like this:

Process "A": start-> User Task-> end.

process A has the data object: "invoiceId"=1

Process "B" start -> (Signal to Process "A" with invoiceId = "1") -> end

process B also has the data object: "invoiceId"=1

Use case would be approximately like that: 

Process A registering new invoice and sends notification to user e.g: "New Incoming Invoice INV_1". The human task can be completed by the assignee OR it can receive a signal from another process and be auto completed.

Another process "B", lets say, it is a Payment receiving process. which received auto payment for an invoice 1. When the payment is received we need to signal Process A to complete. 

I just cant find any tutorials of how to define a signal throwing and catching between two processes based on some kind of correlation id.

 

thank you in advance! 

5 Replies
vipi_voxa
Member II

Re: How to signal another process?

OK i guess it;s time for me to answer my own question. Please advice me if there is more trivial solution in place.

What i did in my mockup. Process A. start -> set business key variable -> User Task -> end

Process A has Signal "globalSignalA" defined 

User Task has Signal Boundary Event with signal reference to "globalSignalA"

Process B : start -> run script (groovy code provided below) -> end

groovy script. gets RuntimeService, collects information about executions with signal subscription: globalSignalA and calls signalEventReceivedAsync (watchout

signalEventReceived wont work). (activiti version: 5.22.0)

This is example of a groovy script i am running, somebody can find it usefull

import org.activiti.engine.runtime.ExecutionQuery
import org.activiti.engine.task.Task
import org.activiti.engine.runtime.ProcessInstance
import org.activiti.engine.RuntimeService
import org.activiti.engine.runtime.ProcessInstanceQuery
import org.activiti.engine.runtime.Execution

RuntimeService runtimeService = processEngine.getRuntimeService();

ProcessInstanceQuery procInstanceQuery = runtimeService.createProcessInstanceQuery()
String lBusinessKey= (String) execution.getVariable('testId')

//gimmi list of active processes by business key

List<ProcessInstance> instances = procInstanceQuery.processInstanceBusinessKey(lBusinessKey).active().list()
int x=0
for (ProcessInstance lProcInstance: instances)
{
x+=1
System.out.println('proc found: ' + lProcInstance.getName() + ', business key=' + lProcInstance.getBusinessKey())
}


if (x==0)
System.out.println('no related active processes found!')

//gimmi executions with globalSignalA by business key

x=0

List<Execution> executions = runtimeService.createExecutionQuery()
.processInstanceBusinessKey(lBusinessKey, true)
.signalEventSubscriptionName("globalSignalA")
.list();

System.out.println('list executions...')
for (Execution exec : executions)
{
x+=1
System.out.println('sending signal to ' + exec.getName() + ' processInstanceId:' + exec.getProcessInstanceId())
// runtimeService.signalEventReceived("globalSignalA", exec.getId());
runtimeService.signalEventReceivedAsync('globalSignalA', exec.getId())
}
System.out.println('signals sent ' + x)
System.out.println('done')

gdharley
Intermediate

Re: How to signal another process?

Maybe I'm missing something but your code appears to get a list of process executions that have a subscription to "globalSignalA" and individually "release" these by signalling them.

If his is truly a global signal, then setting the signal listeners to the default of "global" scope means that as soon as an intermediate send signal event is sent, all listeners will fire automatically. You really shouldnt need to write code to satisfy this use case.

Greg

vipi_voxa
Member II

Re: How to signal another process?

No-no it is probably me who is missing something. What is a signal listener - have not found one in the activiti user guide, and how to make it to listen for the (global) signal also based on business key or some other correlation id?

I tried signalintermediatecatchevent and signal boundary events none of them fires when the other process throws the signal. (unless i do my groovy code).

gdharley
Intermediate

Re: How to signal another process?

Actually, the "real" name is an Intermediate Signal Throw event:

Make sure your signal definition is "global" scoped and you should be golden.

Greg

vipi_voxa
Member II

Re: How to signal another process?

Hi Greg, Thank you for the taking a look at my question and quick responses! 

Well yes throwing and catching signals are working ok. But it seems not to be what i am asking for. I will try to rephrase, maybe i was not that clear at the first place.

Here is example and output from my processes. 

What I am doing: (based on your proposed solution):

Process B starts -> sets business key id to '2'-> send HT to kermit (with boundry to global signal A) 

Process A starts -> sets business key id to '1' -> throws (global singal A)

What I need: Process B with business key 2, stays active (is not receiving a signal), because it has different business identification. 

What i got: 

[Server:common-server] 10:50:42,989 [default task-27] INFO stdout - Process B (358392). Set Business key to: 2
[Server:common-server] 10:50:42,990 [default task-27] INFO stdout - Process B (358392). Sending H Task to mr. Kermit.
[Server:common-server] 10:50:50,365 [default task-28] INFO stdout - Process A (358402). Set business key to: 1
[Server:common-server] 10:50:50,366 [default task-28] INFO stdout - Process A (358402). Sending signal...
[Server:common-server] 10:50:51,070 [default task-28] INFO stdout - Process B (358392). Closing HT because signal is
received.
[Server:common-server] 10:50:51,072 [default task-28] INFO stdout - Process B (358392). By I am done.
[Server:common-server] 10:50:51,231 [default task-28] INFO stdout - Process A (358402). Done.

Just to stress one more time - The main point in my requirement is that i need to send signals only and only to related (by some correlation id) processes. (not to all processes which are waiting for global signal). Meanwhile i don't see any other ops for that only but running kinda script i gave example earlier. 

thank you!