Global Event Listener - Deletion Event

Hi everyone,

I am using Camunda (Spring Boot) and want to have a global listerner, which is activated everytime a process instance is deleted. More precisely, the listerner should trigger, no matter in which process the instance gets delted. I have seen the spring event bridge but I am not sure how to use it properly in this usecase.

Best regards
Jonathan

@Jonathan_H You can refer this post.

Additionally, in the respective methods you can check for the type of event like below:

@Slf4j
@Component
public class CamundaEventListeners {

	@EventListener
	public void onTaskEvent(DelegateTask taskDelegate) {
		String eventType = taskDelegate.getEventName();
		log.info("onTaskEvent##DelegateTask##Event {} triggered", eventType);
		if (TaskState.STATE_DELETED.name().equals(taskDelegate.getEventName())) {
			// implementation code goes here
		}
	}

	@EventListener
	public void onTaskEvent(TaskEvent taskEvent) {
		String eventType = taskEvent.getEventName();
		log.info("onTaskEvent##TaskEvent##Event {} triggered", eventType);
		if (TaskState.STATE_DELETED.name().equals(taskEvent.getEventName())) {
			// implementation code goes here
		}
	}

	@EventListener
	public void onExecutionEvent(DelegateExecution executionDelegate) {
		String eventType = executionDelegate.getEventName();
		log.info("onExecutionEvent##DelegateExecution##Event {} triggered", eventType);
	}

	@EventListener
	public void onExecutionEvent(ExecutionEvent executionEvent) {
		String eventType = executionEvent.getEventName();
		log.info("onExecutionEvent##ExecutionEvent##Event {} triggered", eventType);
	}

	@EventListener
	public void onHistoryEvent(HistoryEvent historyEvent) {
		String eventType = historyEvent.getEventType();
		log.info("onHistoryEvent##HistoryEvent##Event {} triggered. Is process Instance Resource deleted?: {}", eventType,
				historyEvent.isEventOfType(HistoryEventTypes.PROCESS_INSTANCE_END));
	}
}

Here’s some sample logs:

[http-nio-8086-exec-7] INFO  c.b.c.e.CamundaEventListeners - onHistoryEvent##HistoryEvent##Event complete triggered. Is process Instance Resource?: false
[http-nio-8086-exec-7] INFO  c.b.c.e.CamundaEventListeners - onHistoryEvent##HistoryEvent##Event end triggered. Is process Instance Resource?: true
[http-nio-8086-exec-7] INFO  c.b.c.e.CamundaEventListeners - onHistoryEvent##HistoryEvent##Event end triggered. Is process Instance Resource?: true
[http-nio-8086-exec-7] INFO  c.b.c.e.CamundaEventListeners - onHistoryEvent##HistoryEvent##Event null triggered. Is process Instance Resource?: false
1 Like

In addition to the previous post: If you want to handle conditions (like "only execute on DELETE): the Eventlistener annotation is a standard spring eventListener, so you can configure its “conditional” attribute to your needs (like conditional="#event.name=DELETE").

1 Like

@aravindhrs Thanks for the clarification. Activating the event listerner is relativly straight forward. :slight_smile: In my tests this PROCESS_INSTANCE_END event trigger not just if you delete a process instance, but also after the completion of the task. I would like to only catch the event of the deletion. It seems like the Java Docs do not offer such an event?

@jangalinski I tried your conditional="#event.name=DELETE" but could it be the case that you ment condition="#event.name=DELETE". And do you know how I can filter for just the deletion of an process instance? Using event.name=DELETE did not work out for me.