The Dkron Scheduler Adapter Library is a user-friendly Spring Boot library, designed as an adapter for the Dkron tool. This library provides convenient job scheduling and execution capabilities within your Spring Boot applications.
- To integrate the Dkron Scheduler Client Adapter Library in your Spring Boot project add to gradle
TODO :)
- Eventually configure properties
scheduler.dkron-server-url
: URL of the dkron server- default :
http://localhost:8081
- (if you are running dkron server on docker remember to map 8080 to 8081,the default port configuration has been changed because it is the default one for the Spring application.)
- default :
scheduler.dkron-rest-api-retry-attempts
: Number of attempts to retry the rest api call to dkron server- default :
3
- default :
scheduler.dkron-rest-api-minimum-backoff-in-milliseconds
: Minimum backoff time in milliseconds between retries- default :
250
- default :
scheduler.job-execution-server-url
: URL of the job execution server, in other words URL of application in network, so that dkron can find it and execute the job.- default :
http://localhost:8080
- default :
To schedule jobs, use the JobScheduler bean and pass an instance of JobDescription to it. Here's a concise example of scheduling a job,
@Component
@RequiredArgsConstructor
class SchedulingExample {
private final JobScheduler jobScheduler;
void scheduleJob() {
String id = UUID.randomUUID().toString();
JobDescription jobDescription = new JobDescription(
id,
new PrintSomethingJobDto("Job %s execution".formatted(id)),
new Schedule.Fixed(Instant.now().plus(Duration.ofSeconds(5)))
);
jobScheduler.scheduleJob(jobDescription);
}
}
jobNotificationPayload
: A POJO (Plain Old Java Object) containing additional information sent as part of the job
execution notification. This object can be any DTO but must adhere to the POJO structure, containing a no-args
constructor, getters, and setters.
By default, this library uses Spring Boot’s event publisher for notifying about job executions. To handle these notifications, create a method annotated with @EventListener and listen for the object passed to JobDescription.
@Component
@Slf4j
class JobExecutionListener {
@EventListener
public void execute(PrintSomethingJobDto printSomethingJobDto) {
log.info("PrintSomething job executed: {}", printSomethingJobDto);
}
}
For custom implementations, provide your own implementation of JobExecutionNotifier.
There is also test tool library for testing pojo compatibility.
// TODO
import com.codibly.schedulerclient.JobNotificationPayloadCompatibilityChecker;
import org.junit.jupiter.api.Test;
class PojoCompatibilityTest {
@Test
void checkIfPojoIsCompatibleWithDkronScheduler(){
// Given
PrintSomethingJobDto helloWorld = new PrintSomethingJobDto("Hello World");
// Then
JobNotificationPayloadCompatibilityChecker.of(helloWorld).verifySerializationCompatibility();
}
}
Main submodule with scheduler client implementation
Submodule with test tool for dkron-scheduler-client
Submodule with example usage of dkron-scheduler-client