A PostgreSQL-backed background job queue built with Java 21 and Spring Boot. Jobs are submitted through REST APIs and processed asynchronously by concurrent, stateless workers.
- Safe concurrent job claiming using
FOR UPDATE SKIP LOCKED - Claim tokens to prevent stale workers from overwriting newer claims
- Delayed retries with configurable attempt limits
- Automatic recovery of abandoned jobs
- Configurable worker pool with graceful shutdown
- REST APIs for job submission, status lookup and filtered listing
- Docker Compose setup with persistent PostgreSQL storage
Java 21 · Spring Boot · Spring JDBC · PostgreSQL · Flyway · Maven · JUnit 5 · Docker · Docker Compose
flowchart LR
Client -->|REST| API[REST API]
API -->|Submit job| DB[(PostgreSQL)]
subgraph Workers
W1[Worker 1]
W2[Worker 2]
W3[Worker N]
end
Workers -->|Claim jobs| DB
Workers --> Handlers[Job handlers]
Recovery[Recovery scheduler] -->|Recover expired claims| DB
stateDiagram-v2
[*] --> PENDING
PENDING --> PROCESSING: claimed
PROCESSING --> COMPLETED: success
PROCESSING --> PENDING: retry or expired claim
PROCESSING --> FAILED: attempts exhausted
COMPLETED --> [*]
FAILED --> [*]
ClaimQ provides at-least-once delivery. Jobs may execute more than once following lease expiration, so handlers should be idempotent.
Requirements: Docker and Docker Compose.
cp .env.example .envSet DB_PASSWORD in the .env file, then run:
docker compose up -d --buildDocker Compose handles the application build, PostgreSQL initialization, networking, health checks and persistent storage. Flyway creates the database schema automatically.
The API is available at http://localhost:8080.
To stop and remove the containers:
docker compose downDatabase records persist across container recreation through a named Docker volume.
Requirements: Java 21 and PostgreSQL 13+.
Create the databases:
CREATE USER claimq_user WITH PASSWORD 'change-me';
CREATE DATABASE claimq OWNER claimq_user;
CREATE DATABASE claimq_test OWNER claimq_user;Configure credentials and run:
export DB_USERNAME=claimq_user
export DB_PASSWORD=change-me
./mvnw spring-boot:run| Method | Endpoint | Description |
|---|---|---|
| POST | /api/jobs |
Submit a job |
| GET | /api/jobs/{id} |
Get job details |
| GET | /api/jobs |
List and filter jobs |
curl -X POST http://localhost:8080/api/jobs \
-H 'Content-Type: application/json' \
-d '{"taskType":"demo","payload":{"msg":"hello"}}'Check job status:
curl http://localhost:8080/api/jobs/1Job submission accepts taskType, payload and an optional maxAttempts (1–10, default 3).
Job listing supports status, page and size query parameters.
| Property | Default |
|---|---|
claimq.worker.count |
3 |
claimq.worker.poll-interval |
1s |
claimq.worker.lease-timeout |
60s |
claimq.recovery.interval |
15000ms |
claimq.retry.base-delay |
5s |
claimq.retry.max-delay |
60s |
claimq.shutdown.grace-period |
30s |
Database configuration is externalized through DB_URL, DB_USERNAME and DB_PASSWORD environment variables.