How to implement activiti signal intermediate catch event

Need to design a process flow such that it will be paused in the middle(after certain usertask) until a external event/process completes and then resumes the flow.

I have chosen to use “Signal intermediate catch event” with signal scope=processinstance (let me know if this is not the right option)…

Ideally the expectation is When the process arrives this stage it waits for external event to complete.

When the external event completes, I need to send signal to the process instance

SignalIntermediateCatchEvent → should consume the signal and continue the process.

Can any share the example java implementations of signal sending and consuming code .

New to the bpmn signal event usage, trying to find examples.

Hi @kdevineni

To send the signal event you can use the RuntimeService:

private RuntimeService runtimeService;

Execution execution = runtimeService.createExecutionQuery().processInstanceId("your process instance id").signalEventSubscriptionName("Name of the Signal").singleResult();
runtimeService.signalEventReceived("Name of the Signal", execution.getId());

The signal can be catched by the Signal Intermediate Catching Event within a process.

Regards,
Simon

Thanks @amporsim .

When I try to send the signal , I receive this error

Execution ‘5250024’ has not subscribed to a signal event with name ‘resumeFlow’.

Assuming something needs to be done before the the send signal is issued.

Attaching my signal test flow below. Has two user tasks with intermediateCatchEvent(for signal resumeFlow) in the middle.
I have the start and end listeners configured to just print the details.

When I start the workflow and approve the usertask1, workflow arriving signalintermediatecatchevent1.

From rest end point I am triggering the executing the send signal code, and I see the execution not subscribed to a signal message…

I am missing the step of subscribing to the signal , can you advice me on how this should be done.

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <signal id="resumeFlow" name="resumeFlow" activiti:scope="processInstance"></signal>
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="Task1"></userTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <intermediateCatchEvent id="signalintermediatecatchevent1" name="SignalCatchEvent">
      <extensionElements>
        <activiti:executionListener event="end" class="com.imagework.flowable.listeners.doccs.SignalEndExecutionListener"></activiti:executionListener>
        <activiti:executionListener event="start" class="com.imagework.flowable.listeners.doccs.SignalStartExecutionListener"></activiti:executionListener>
      </extensionElements>
      <signalEventDefinition signalRef="resumeFlow"></signalEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="signalintermediatecatchevent1"></sequenceFlow>
    <userTask id="usertask2" name="User Task"></userTask>
    <sequenceFlow id="flow3" sourceRef="signalintermediatecatchevent1" targetRef="usertask2"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow4" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
  </process>
 
</definitions>

I am playing around this I tried with processInstanceId and executionId without any luck.

runtimeService.signalEventReceived(“Name of the Signal”, processInstanceId); >> Execution ‘5250024’ has not subscribed to a signal event with name ‘resumeFlow’. >> this is not correct.

runtimeService.signalEventReceived(“Name of the Signal”, execution.getId()); >> code runs without errors, but signalintermediatecatchevent1 doesn’t receive the event/trigger. >> I am missing something here.

I tried the below case, when I have signalintermediatecatchevent created(& waiting), if the signalintermediatethrowevent is fired by completing Task1, then the signalintermediatecatchevent is picking up the event.

I am not sure what I am missing here for signal triggering., please advice

Hi @kdevineni

If you change the signal scope from processInstance to global it should work.

<signal id="resumeFlow" name="resumeFlow" activiti:scope="global"></signal>

Test case:

    @Test
    public void test(){
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess");

        Task task = taskService.createTaskQuery().taskDefinitionKey("usertask1").processInstanceId(processInstance.getProcessInstanceId()).singleResult();
        taskService.complete(task.getId());

        Execution execution = runtimeService.createExecutionQuery()
                .processInstanceId(processInstance.getProcessInstanceId())
                .signalEventSubscriptionName("resumeFlow")
                .singleResult();
        runtimeService.signalEventReceived("resumeFlow", execution.getId());

        assertThat(taskService.createTaskQuery().taskDefinitionKey("usertask2").processInstanceId(processInstance.getProcessInstanceId()).singleResult())
                .isNotNull();
    }

Regards,
Simon

@amporsim Thank you .
Changing scope from processinstance to global worked.