Shedlock Mongo Reactive Provider

Shedlock Mongo Reactive provider give the ability to apply distributed locks using a mongo database using reactive mongo client.

Installation

If you want to use this extension, you need to add the io.quarkiverse.shedlock:quarkus-shedlock-provider-mongo-reactive extension first to your build file.

For instance, with Maven, add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.shedlock</groupId>
    <artifactId>quarkus-shedlock-provider-mongo-reactive</artifactId>
    <version>0.0.3</version>
</dependency>

Configuring

The quarkus.shedlock.defaults-lock-at-most-for application property is mandatory. The collection naming is defined to shedlock and cannot be overridden. The database name is defined to shedlock and it is possible to override it depending on the mongo client name.

src/main/resources/application.properties
quarkus.shedlock.defaults-lock-at-most-for=PT30S
quarkus.shedlock.mongo-reactive.cluster1.database-name=customDatabase

Extension Configuration Reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

how long the lock should be kept in case the executing node dies

Environment variable: QUARKUS_SHEDLOCK_DEFAULTS_LOCK_AT_MOST_FOR

string

required

value which is much longer than normal execution time

Environment variable: QUARKUS_SHEDLOCK_DEFAULTS_LOCK_AT_LEAST_FOR

string

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

Mongo client configuration

Type

Default

quarkus.shedlock.mongo-reactive."mongoclient-name".database-name

database name for mongo client (default to shedLock)

Environment variable: QUARKUS_SHEDLOCK_MONGO_REACTIVE_DATABASE_NAME

string

shedLock

How to use it

To activate the lock on a method just annotate it with @MongoReactiveSchedulerLock.

import jakarta.enterprise.context.ApplicationScoped;

import io.quarkiverse.shedlock.providers.mongo.reactive.runtime.runtime.MongoReactiveSchedulerLock;

@ApplicationScoped
public class MongoReactiveSchedulerLockService {
    @MongoReactiveSchedulerLock
    public void runUsingLock() {
        // do something
    }
}

By default, the lock is bound to the default mongo client.

The lock duration and mongoClientName can be defined on the annotation directly likes this way:

import jakarta.enterprise.context.ApplicationScoped;

import io.quarkiverse.shedlock.common.runtime.LockDuration;
import io.quarkiverse.shedlock.providers.mongo.reactive.runtime.runtime.MongoReactiveSchedulerLock;

@ApplicationScoped
public class MongoReactiveSchedulerLockServiceOptions {
    @MongoReactiveSchedulerLock(mongoClientName = "cluster1reactive", lockDuration = @LockDuration(lockAtMostFor = "PT30S", lockAtLeastFor = "PT10S"))
    public void runUsingLock() {
        // do something
    }
}