Adding a Spring event listener to the Camunda BPM Run Docker

Viewed 922

I'd like to do some work triggered by Camunda process instance state changes and as such have written a Spring annotation-driven event listener for Camunda.

I've packaged it into a JAR file: code and pom.xml are on Gist here.

I've written a Dockerfile that extends camunda/camunda-bpm-platform:run-7.14.0 and am poking the resulting JAR into /camunda/configuration/userlib.

This is definitely in the Spring boot loader path, according to ps:

10 camunda   0:31 java -Dloader.path=/camunda/internal/webapps/,/camunda/internal/rest/,/camunda/configuration/userlib/,/camunda/configuration/keystore/ -Dcamunda.deploymentDir=/camunda/configuration/resources -jar /camunda/internal/camunda-bpm-run-core.jar --spring.config.location=file:/camunda/configuration/default.yml

Inspecting the log, Camunda is definitely firing up Spring eventing:

o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-001: Initialized Camunda Spring Boot Eventing Engine Plugin.
o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-003: Task events will be published as Spring Events.
o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-005: Execution events will be published as Spring Events.
o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-007: History events will be published as Spring events.

But I am seeing none of my log messages.

This leads me to suspect that simply dropping a JAR on the loader isn't quite enough for Spring Boot to find the listener - but I don't know what else I'm missing.

Any help would be much appreciated. Thanks!

2 Answers

OK, I realised what I was doing wrong here. I was under the mistaken assumption that any JAR files on the classpath would automatically have their classes initialised, which would in turn mean Spring would notice the @Component and @EventListener annotations and then... Do Some Magic to add the listener. This is not true.

I now understand that the right thing to do is to use the Camunda Initializr to build an entirely new Spring Boot application that includes my listener and then roll a Docker around that. So that's my path forward now.

You only need to make sure that any Spring components you declare fall under the configured Spring component scan @see e.g. https://www.baeldung.com/spring-component-scanning

In your case this probably only means that you need to adjust the package name to be a sub-package of the package of the Application class. Alternatively you can add configuration to extend the Spring component scan to your packages.

Related