Get origin of a Boundary Event

Hi, there,

I am trying to implement a timeout for a ServiceTask using a BoundaryEvent. I have added a “Non blocking Time Boundary Event” to my ServiceTask.

diagram

In the listener I need to have access to the Activity-Instance-Id (MyService instace) where the event has been originated. I’ve tried what’s suggested in this thread but I got allways null.

public void notify(DelegateExecution delegateExecution) {
    ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution;

    Job jobTimer = processEngine.getManagementService()
                            .createJobQuery()
                            .processInstanceId(executionEntity.getProcessInstanceId())
                            .activityId(executionEntity.getCurrentActivityId())
                            .singleResult(); // I get BounderyEvent
                    
    Task task = processEngine.getTaskService()
                             .createTaskQuery()
                             .executionId(jobTimer .getExecutionId())
                             .singleResult(); // always is null
}

Can someone help me?

Regards

Hi @joseluisluri,

this code doesn’t work because you don’t have a user task. The TaskService is only responsible for user tasks, not service tasks.

You could use the activity instance tree to find the activity instance id of the task.

runtimeService.getActivityInstance(job.getProcessInstanceId)

Why do you want to access the activity instance id?

Best regards,
Philipp

Hi @Phillipp_Ossler,

thanks for your answer, I found it useful. In our project, each ServiceTask represents a async microservice and we use the Task-Id to identify each request.

In the execute phase of the Activity, we send a message to an ActiveMQ queue and expect a response in a limited time. If there is no response within a set time (response trigger signal event) we want to trigger a Timeout event (BoundaryEvent in that case) in order to know which request was failed.

I’m sorry, I need the Activity-Id, not the Activity-Instance-Id. Finally I’m doing something like this. I don’t know if that’s the best way but it works.

public void notify(DelegateExecution delegateExecution) {   
     ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution;

     Job jobTimer = processEngine.getManagementService()
                            .createJobQuery()
                            .processInstanceId(executionEntity.getProcessInstanceId())
                            .activityId(executionEntity.getCurrentActivityId())
                            .singleResult();

    String activityInstanceId = job.getExecutionId();
    String activityId = processEngine.getRuntimeService().getActiveActivityIds(activityInstanceId).get(0);
    // controlCenterService.warn(activityId, "Timeout exceeded");
}

Regards