Extending Camunda BPM Run Docker with custom listener

Hi all,

I would like Camunda to notify an external service via REST every time a task changes hands. The rest of this post is based on the assumption that this functionality is not baked in and that I’ll have to write a custom task listener, but if I’m mistaken please tell me as I will be very glad to sidestep the extra effort :slight_smile:

Assuming I need to write a custom task listener, I have found the code examples here (email example) and here (parse listener example) but both examples seem to assume you’re building the distribution yourself with Maven.

Our current Camunda deployment uses the BPM Run Docker image. Inspecting the contents of the Docker it seems that all I have are pre-built JARs (camunda-bpm-run-core.jar, camunda-bpm-spring-boot-starter-rest-<version>.jar, etc) and the two configuration files default.yml and production.yml; AFAICT I do not have access to camunda.cfg.xml as mentioned here.

I have no experience with Spring Boot and it’s not clear to me how to wire everything together. Can someone walk me through the build and deploy process? I’m assuming the workflow is something like:

  1. Yank the JAR out of the BPM Run Docker to compile against.
  2. Write a simple event listener and package it into its own JAR.
  3. Poke the JAR into the Docker and edit /camunda/start.sh to add my JAR to the classpath.
  4. Use some configuration somewhere to tell Camunda to load my custom listener.

Questions

Is writing the event listener as simple as I stated in #1 or are there gotchas I need to be aware of?

Once I have a JAR containing my listener, how do I tell Camunda that it exists? Does that get added in the .yml configuration files or do I need to add configuration to my JAR? If so, where and how?

TIA!

1 Like

Hi @helgridly

This is some functionality that has been coming up a lot in the last while. There are a lot a possible solutions and i think one that people go to a lot (if using spring boot) is to use the Spring Eventing Bridge to grab the events as they happen in the spring boot application and then do what you’d like to. I haven’t done this myself but it seems like a much easier way than building a plugin.

Camunda BPM Run does use spring boot behind the scenes so there might a good way to get this working on that distro as well.

Thanks Niall. I took a stab at this without success; mind taking a look?

See this gist for my Java listener and pom.xml. As you can see, all they do is log when one of the callbacks is fired.

I rolled this into a jar and poked it into /camunda/configuration/userlib in the Docker, which if I’m reading start.sh right should be on the classpath (the top of the logs seem to confirm this too).

None of my messages show in the logs when I add a new BPMN deployment, start a process, or complete any user tasks. At startup, I do see these logs, which at least say that eventing is enabled - though if it’s loading my listener it’s not saying anything about it.

2021-01-05 19:14:35.929  INFO 11 --- [           main] org.camunda.bpm.spring.boot              : STARTER-SB021 Auto-Deploying resources: []
2021-01-05 19:14:35.937  INFO 11 --- [           main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-001: Initialized Camunda Spring Boot Eventing Engine Plugin.
2021-01-05 19:14:35.937  INFO 11 --- [           main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-003: Task events will be published as Spring Events.
2021-01-05 19:14:35.937  INFO 11 --- [           main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-005: Execution events will be published as Spring Events.
2021-01-05 19:14:35.943  INFO 11 --- [           main] o.c.b.s.b.s.event.EventPublisherPlugin   : EVENTING-007: History events will be published as Spring events.

Any ideas what I’m missing or where I can look next? Thanks!

(Apologies if this is a breach of etiquette but having searched through old posts I think @aravindhrs or @rob2universe may have an answer!)

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.

1 Like

Thanks for letting us know how you’re getting on with this.
If you end up creating some code useful to share please feel free to post up a link, it’ll likely be very helpful.

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 Application class. Alternatively you can add configuration to extend the Spring component scan to your packages.

1 Like

@helgridly
Can you provide us a clear steps for doing this successfully, please?

I’m new in Camunda and java

Here is a full example showing how to create a plugin jar, which also adds Spring components: code/snippets/run-engine-plugin at master · camunda-consulting/code · GitHub

This project shows how to add a jar to the Docker image GitHub - rob2universe/bpmrun-add-to-dockerimg
You can ignore the Azure parts, just see POM
bpmrun-add-to-dockerimg/pom.xml at f1493ad10b2766dff65782ad13abb286e33c1095 · rob2universe/bpmrun-add-to-dockerimg · GitHub
and
Dockerfile:
bpmrun-add-to-dockerimg/Dockerfile at f1493ad10b2766dff65782ad13abb286e33c1095 · rob2universe/bpmrun-add-to-dockerimg · GitHub