This repository shows an example how you can integrate JobRunr and Quarkus.
This project has the following packages:
- org.jobrunr.examples: this package contains 3 classes:
JobRunrExampleApplication
: the EE application that defines the context path
- org.jobrunr.examples.services: this package contains MyService, a simple ApplicationScoped service with two example methods which you can run in the background.
- org.jobrunr.examples.webap.api: this package contains the following http resource:
JobResource
: this resource contains two REST api's which allows you to enqueue new Background Jobs
- clone the project and open it in your favorite IDE that supports Maven
- Run the Maven plugin
mvn quarkus:dev
and wait for Quarkus to be up & running - Open your favorite browser:
- Navigate to the JobRunr dashboard located at http://localhost:8000/dashboard.
- To enqueue a simple job, open a new tab and go to http://localhost:8080/jobs/ and take it for there.
- Visit the dashboard again and see the jobs being processed!
Quarkus is optimized for GraalVM and JobRunr supports this, except for enqueueing lambdas using the jobscheduler because of ASM analysis trickery. To see how this works, you can compile this example project natively (see the Quarkus documentation for more details):
- Install a GraalVM VM and have
GRAALVM_HOME
set up - Build the project using
quarkus build --native
or./mvnw install -Dnative
. The native profile in thepom.xml
has native specific properties enabled. - in
target
, you should find an executable calledexample-quarkus-1.0.0-SNAPSHOT-runner
. - Try to schedule jobs using different ways by clicking on the links in http://localhost:8080/jobs/.
If you run into this exception:
Caused by: java.lang.NoSuchMethodException: org.jobrunr.examples.webapp.api.JobResource$$Lambda/0x599e42de00e955732588625a22221761.writeReplace()
at java.base@23.0.2/java.lang.Class.checkMethod(DynamicHub.java:1158)
at java.base@23.0.2/java.lang.Class.getDeclaredMethod(DynamicHub.java:1284)
at org.jobrunr.jobs.details.SerializedLambdaConverter.toSerializedLambda(SerializedLambdaConverter.java:28)
You have attempted to schedule a lambda in native mode and JobRunr cannot analyse the metadata to store the job. Instead, rely on @Job
or the job request method and avoid injecting and using the JobScheduler
directly.
If you do not want to enable the dashboard (or the background job server that processes jobs) on a particular cluster, you can disable packaging in these features by specifying this in your application.properties
---see the JobRunr Quarkus Extension docs:
quarkus.jobrunr.background-job-server.included=false
quarkus.jobrunr.dashboard.included=false
Using Oracle GraalVM 23.0.2 on a macOS ARM64 machine, the binary sizes for this example project are:
- Everything included:
91M
- Dashboard disabled and excluded:
89M
- Background job server disabled and excluded:
90M
- Everything excluded:
88M