19. April 2021
timer-icon 3 min

The Camunda External Client for Micronaut

Do you want to have your Camunda External Task Worker up and running in milliseconds? Together with Micronaut and GraalVM your external task worker will start instantly!
External Task Pattern with Micronaut


Do you want to have your Camunda External Task Worker up and running in 35ms? Together with with Micronaut and GraalVM your external task worker will start instantly and communicate via REST with any Camunda based server. Read on for the whole story!

Camunda is great for process automation and has a very good developer experience. For example you can run Camunda as an embedded process engine inside your microservice. You could either use the Camunda Spring Boot Starter or (we’re biased 🙂 ) preferably the Micronaut Camunda Integration. There are quite a few good reasons to use the external task pattern in your processes: separation of concerns, decoupling from the process, horizontal scaling, free choice of programming language, …

With the external task pattern you externalize the service task logic to a separate application which fetches tasks, processes them, and returns the result. The tasks are processed asynchronously by the workers, so no threads are blocked in the process engine and no incidents occur if a worker is temporarily unavailable. The process will then handle reported errors, timeouts, and take care of the next steps.

Actually, you could simply use Camunda’s External Client for Java in your Micronaut application. However, this would require some boilerplate code and configurability would also need to be implemented as needed. Therefore, we started an open source project which makes it as simple as pulling in a dependency, implementing an interface, and setting some configuration properties.

You can find the open source project on GitHub: https://github.com/NovatecConsulting/micronaut-camunda-external-client

Note: the communication between the the external task worker and the main process application happens via REST. So you can run the client on Micronaut and the main process application on any technology (Micronaut, Camunda Platform Run, Spring Boot, …).

Implement a Worker

Micronaut is a JVM-based microframework to build microservices. It’s kind of similar to Spring Boot but optimised in terms of resource usage.

If you don’t have an existing Micronaut project, create a new project using Micronaut Launch.

Add the dependency, e.g. with Gradle (Maven also works):

Then implement the interface “org.camunda.bpm.client.task.ExternalTaskHandler” and declare the class as a bean using the “@Singleton” annotation , e.g.

You also need to configure the base URL, e.g. in your application.yml:

This can then be built as a Fat/Uber/Shadow JAR and started:

Start-up time is about 850ms which is quite good. However, this can be improved with GraalVM – read on!

Running on GraalVM

Micronaut applications can be compiled as native applications using GraalVM. With GraalVM the Micronaut based external worker will start up in about 35 milliseconds and use even less memory.

There are some drawbacks: the compilation takes a few minutes and the application will only run on a single platform (you could put this in a Docker image to run it anywhere).

A good use case for minimal start up times and memory usage is the cloud where you can scale your army of workers up and down as needed. The workers will be available almost instantly and use less memory – thereby reducing costs. So even if the startup time is not critical for you, the reduced memory consumption should convince anyone deploying to the cloud.

You can find more details regarding setup, configuration, and build at https://github.com/NovatecConsulting/micronaut-camunda-external-client#graalvm

Try it Out!

Jump to the “Getting Started” section of https://github.com/NovatecConsulting/micronaut-camunda-external-client to implement your first worker! You will also find more examples there.

You’re welcome to try this out and we’d love to hear your feedback and discuss your ideas!

And as always: we’re happy to support you with our BPM Technology Consulting.

Comment article