Transaction plugin
Enjoy support for @Transactional out of the box in your preferred development framework
The JobRunr Spring Boot Starter, Micronaut integration, Quarkus extension come with an @Transactional
plugin that makes sure your jobs join the transaction created by the framework. You can also benefit from this plugin when using Kotlin with the Exposed ORM.
Also works with Exposed’s transaction block!
How does it work?
- the JobRunr Spring Boot Starter and Micronaut Integration, Quarkus Extension, Exposed Plugin check whether they can participate in a transaction created by that framework.
- if one is present, it is used and the whole method is transactional.
- if not, JobRunr creates it’s own transaction to make sure the job is saved to the database.
This of course only works for the SQL
StorageProvider
s.
Configuration
In most cases, you have nothing to do. JobRunr Pro is able to join any ongoing transaction started by your preferred framework.
The one exception is when you want to use Exposed. But you’ll be up and running just by applying the following steps:
- Add
jobrunr-pro-kotlin-XX-support
as a dependency (replaceXX
by a Kotlin version supported by JobRunr, e.g,jobrunr-pro-kotlin-2.0-support
).
Note: JobRunr officially only supports the last two versions of Kotlin. Make sure to regularly check that your version is still supported.
- Configure the connection provider, depending on your situation:
- You’re using a JobRunr Pro Spring Starter (e.g,
jobrunr-pro-spring-boot-3-starter
): make sure Exposed is on your classpath. JobRunr Pro automatically configures the plugin for you as long as Exposed is on your classpath. - You’re using JobRunr Pro without Spring Boot or you prefer to use the fluent API: you need to provide a
ExposedTransactionAwareConnectionProvider
to theStorageProvider
. See below, for how to achieve this.
- You’re using a JobRunr Pro Spring Starter (e.g,
Programmatically configure a Transaction Plugin
If you’re using one of the supported frameworks (Spring, Micronaut or Quarkus), then you may provide a ConnectionProvider
bean that will be picked up automatically by JobRunr.
If you’re using the Fluent API, you can configure a ConnectionProvider
as follows:
Similarly you can provide a
ConnectionProvider
for Micronaut, Quarkus and Spring. JobRunr Pro comes with the following transaction aware connections:ExposedTransactionAwareConnectionProvider
,MicronautTransactionAwareConnectionProvider
,QuarkusTransactionAwareConnectionProvider
, andSpringTransactionAwareConnectionProvider
.