This repository demonstrates how to schedule jobs in Spring Boot application with Quartz Clustered mode.
- Retry Pattern With Exponential Back-Off
- Quartz Clustered Mode
- PostgreSQL DB
- Flyway
- Docker / Docker Compose
- Java 11
- Docker
Build docker image
./gradlew bootBuildImage
- Start services.
cd docker docker compose up -d
- Check if all services are running.
docker compose ps
- Schedule new todo job.
curl --location --request POST 'http://localhost:8080/api/v1/todos' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": 2 }'
- Simulate failure.
curl --location --request POST 'http://localhost:8080/api/v1/todos' \ --header 'Content-Type: application/json' \ --data-raw '{ "id": 1 }'
- Check logs and verify if retry with exponential backoff works.
docker compose logs -f # ... # 2022-04-08 08:40:35.884 ERROR 84542 --- [z-demo_Worker-1] com.rbiedrawa.app.todos.TodoJob : Todo [1] is odd - simulating failure😈 # 2022-04-08 08:40:35.888 ERROR 84542 --- [z-demo_Worker-1] c.r.app.core.scheduler.RetryableJobBean : Job todoGroup.todoJob-1 failed with exception. Rescheduling... # java.lang.RuntimeException: Todo 1 is odd # 2022-04-08 08:40:35.920 INFO 84542 --- [z-demo_Worker-1] c.r.app.core.scheduler.RetryableJobBean : Successfully rescheduled job todoGroup.todoJob-1 using new trigger todoGroup.todoJob-1 # # 2022-04-08 08:40:39.931 ERROR 84542 --- [z-demo_Worker-2] com.rbiedrawa.app.todos.TodoJob : Todo [1] is odd - simulating failure😈 # 2022-04-08 08:40:39.931 ERROR 84542 --- [z-demo_Worker-2] c.r.app.core.scheduler.RetryableJobBean : Job todoGroup.todoJob-1 failed with exception. Rescheduling... # java.lang.RuntimeException: Todo 1 is odd # 2022-04-08 08:40:39.954 INFO 84542 --- [z-demo_Worker-2] c.r.app.core.scheduler.RetryableJobBean : Successfully rescheduled job todoGroup.todoJob-1 using new trigger todoGroup.todoJob-1 # ...
- Open Adminer and investigate database structure. Connection details:
- System: PostgresSQL
- Server: db
- Username: demo
- Password: demo
- Database: demo
- Stop services.
docker compose down -v
For further reference, please consider the following sections:
Distributed under the MIT License. See LICENSE
for more information.