06-05-2017 04:59 AM
Hi I am trying to implement event based - gateway as shown in example of activiti user guide Activiti User Guide .
Only difference in below mentioned image and my model is that there is a service task (lets call it task T) between start event and event-based gateway.
I am firing event in this service task T as:
runtimeService.signalEventReceived("signalEvent" , execution.getId());
But its not working and control flow is not going to user task : Handle alert
I also want that this alert goes to event gateway of this process instance and not to any other execution.
Can anyone help?
<definitions id="definitions" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" targetNamespace="Examples"> <signal id="alertSignal" name="alert" /> <process id="catchSignal"> <startEvent id="start" /> <sequenceFlow sourceRef="start" targetRef="gw1" /> <eventBasedGateway id="gw1" /> <sequenceFlow sourceRef="gw1" targetRef="signalEvent" /> <sequenceFlow sourceRef="gw1" targetRef="timerEvent" /> <intermediateCatchEvent id="signalEvent" name="Alert"> <signalEventDefinition signalRef="alertSignal" /> </intermediateCatchEvent> <intermediateCatchEvent id="timerEvent" name="Alert"> <timerEventDefinition> <timeDuration>PT10M</timeDuration> </timerEventDefinition> </intermediateCatchEvent> <sequenceFlow sourceRef="timerEvent" targetRef="exGw1" /> <sequenceFlow sourceRef="signalEvent" targetRef="task" /> <userTask id="task" name="Handle alert"/> <exclusiveGateway id="exGw1" /> <sequenceFlow sourceRef="task" targetRef="exGw1" /> <sequenceFlow sourceRef="exGw1" targetRef="end" /> <endEvent id="end" /> </process> </definitions>
06-05-2017 08:32 AM
You should specify executionId by ExecutionQuery().signalEventSubscriptionName.
Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).signalEventSubscriptionName("alert").singleResult();
runtimeService.signalEventReceived("alert", execution.getId());
06-05-2017 10:09 AM
Value of execution variable is coming as Null in above solution also.
Is there anything wrong in use of "Alert" and "alert"? also in xml both intermediate catch event have name as "Alert" but different id. Is this correct?
06-05-2017 10:26 AM
I tried using all id and name of all signal, signalEvent and timerEvent, i also tried by changing name of Alerts to two different names but in all cases execution is null.
I am using activiti 5.18
06-05-2017 10:34 AM
my updated xml:
Inside "Service Task" I am triggering event.
<?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="Examples" id="definitions">
<signal id="alertSignal" name="alert"></signal>
<process id="catchSignal" isExecutable="true">
<startEvent id="start"></startEvent>
<eventBasedGateway id="gw1"></eventBasedGateway>
<sequenceFlow id="sequenceFlow-3051249c-7a8d-4664-b555-3d2dbad2cd87" sourceRef="gw1" targetRef="signalEvent"></sequenceFlow>
<sequenceFlow id="sequenceFlow-f7c70e01-8a9d-401f-891a-86ac6adba48d" sourceRef="gw1" targetRef="timerEvent"></sequenceFlow>
<intermediateCatchEvent id="signalEvent" name="Alert">
<signalEventDefinition signalRef="alertSignal"></signalEventDefinition>
</intermediateCatchEvent>
<intermediateCatchEvent id="timerEvent" name="Alert">
<timerEventDefinition>
<timeDuration>PT10M</timeDuration>
</timerEventDefinition>
</intermediateCatchEvent>
<sequenceFlow id="sequenceFlow-63cbfd19-ba5a-4731-a55c-465e63864847" sourceRef="timerEvent" targetRef="exGw1"></sequenceFlow>
<sequenceFlow id="sequenceFlow-a89c2ece-3118-4dc1-b060-0e95df0579de" sourceRef="signalEvent" targetRef="servicetask1"></sequenceFlow>
<exclusiveGateway id="exGw1"></exclusiveGateway>
<sequenceFlow id="sequenceFlow-d97bc397-6f10-4748-a787-8e4d18ee1ea4" sourceRef="servicetask1" targetRef="exGw1"></sequenceFlow>
<sequenceFlow id="sequenceFlow-f1a30ab8-6521-4f8b-af60-84dc23fac33c" sourceRef="exGw1" targetRef="end"></sequenceFlow>
<endEvent id="end"></endEvent>
<serviceTask id="servicetask1" name="Handle alert" activiti:delegateExpression="${logRetryErrorJ}"></serviceTask>
<serviceTask id="servicetask2" name="Service Task" activiti:delegateExpression="${createNewAffliateTask}"></serviceTask>
<sequenceFlow id="flow1" sourceRef="start" targetRef="servicetask2"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="servicetask2" targetRef="gw1"></sequenceFlow>
</process>
</definitions>
06-05-2017 02:15 PM
Are you acquiring the execution of signal event from servicetask2?
You cannot acquire because there is no execution of signal event at the stage of servicetask2.
06-05-2017 11:50 PM
okay, what will be the right way to do this, can you please help? am stuck on this past 2 days just trying various permutations.. somehow google is not able to help me.
My service task 2 class: What should I have done differently here? Do i need to create some other class for event gateway or something?
@Component("createNewAffliateTask")
public class CreateNewAffliateTask implements JavaDelegate {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private RuntimeService runtimeService;
@Override
public void execute(DelegateExecution execution) throws Exception {
try {
String companyName = execution.getVariable(Constants.ONBOARDING_COMPANY_NAME, String.class);
String companyPan = execution.getVariable(Constants.ONBOARDING_COMPANY_PAN, String.class);
String employeeEmail = execution.getVariable(Constants.ONBOARDING_EMPLOYEE_EMAIL, String.class);
String executionId = execution.getId();
Execution executions = runtimeService.createExecutionQuery().processInstanceId(execution.getProcessInstanceId())
.signalEventSubscriptionName("alert").singleResult();
runtimeService.signalEventReceived("alert", execution.getId()); //TRIGGERING EVENT HERE
} catch (Exception ex) {
String processInstanceId = execution.getProcessInstanceId();
runtimeService.suspendProcessInstanceById(processInstanceId);
throw new ActivitiException("", "Exception encountered for process id: " + String.valueOf(processInstanceId));
}
}
}
06-06-2017 05:36 AM
You cannot acquire the execution of signal event because there is no execution of signal event at the stage of servicetask2.
You should execute ExecutionQuery after the execution of signal event was generated.
I made a sample.
https://github.com/daisuke-yoshimoto/message_signal_samples
Explore our Alfresco products with the links below. Use labels to filter content by product module.