How to listen to process start, suspend, cancel and end events via CDI event bridge

I’m using the CDI event bridge to have process agnostic way to trigger service invocations. For activities this works well via annotations like @Observes @CreateTask(“taskId”) and the like.

Unfortunately, I haven’t been able to find a straight forward way to listen to more generic events like a process start, suspend, cancel or end events without declaring the listeners in the BPMN itself. One workaround I’m using right now for example is to catch process instance end events is to listen to the generic BusinessProcessEvent and check if the type is an END_ACTIVITY and the injected BusinessProcess is actually ended. It looks something like this:

@Inject
private BusinessProcess businessProcess;

public void onProcessEvent(@Observes BusinessProcessEvent businessProcessEvent) {
    if (businessProcessEvent.getType().equals(BusinessProcessEventType.END_ACTIVITY)
            && businessProcess.getProcessInstance().isEnded()) {
        // do something
    }
}

I was hoping for something along the line of a @StartProcess annotations that would make it easy to listen only to the desired events. Is there another way that I’m overlooking right now?

Last time I tried to achieve this with CDI, I failed and gave up. That’s why I created https://github.com/camunda/camunda-bpm-reactor , a community extension using the projectreactor eventBus.

It allows fine granular filtering of events and should be easy to integrate with cdi ( I only tried spring so far), just register your bean to the bus in the postConstruct method. done.

That sounds interesting, thanks for your input! I will have a look at the project. Haven’t worked with Project Reactor but it seems to be a nice solution.

Regarding the existing event bridge I found the now closed PR. It looks like you hit a technical limitation with duplicate qualifiers there. From your point of view, is it still worth to have a second look at it? I really think this is something that should be possible without an extension (Well, not quite right, as CDI is an extra package anyway.).

My problem was, that I was not able to use Observes with Qualifiers in a way that I could filter on process and event level. I could either do “for all create events whereever they happen” or “for all in this process”, but not “for all TaskAssign events in Process_A do …”

The Topic/Selector in reactor-bus is much more flexible.

But you are right: just because I gave up doesn’t mean you shouldn’t succeed … I believe CDI has a new version meanwhile, right? (I switched to spring mostly the last year so I somehow lost inside).

BTW: I just yesterday did a spring-extension for the reactor extension, allowing to use Beans and automatically get the reactor-bus events. It would be easily possible to also provide a CDI extension to ease integration with JEE.

Right now, it looks like there are more benefits in using reactor. I will definitely have a closer look at it. I’m not even sure the CDI bridge works with CMMN activities right now? If not, this would be a unique selling point for your reactor extension anyway. Thanks again!

1 Like