Spring Boot example app using NATS / JetStream as the Rqueue backend, mirroring
rqueue-spring-boot-example (which uses Redis).
The application code is identical to the redis example modulo two small things:
- Delayed and periodic enqueue endpoints are removed. The v1 NATS broker doesn't model
delayed or scheduled delivery — the redis backend's ZSET schedulers don't exist on the NATS
side, and the broker throws
UnsupportedOperationExceptionfor those calls. application.propertiesselects the NATS backend viarqueue.backend=natsand pointsrqueue.nats.connection.urlat a JetStream-enablednats-server.
Backend selection is a property switch only — the listener / controller / domain code is unchanged from the redis example, which is the whole point of the pluggable-backend split.
Start a JetStream-enabled NATS server (any one of these works):
# native binary
nats-server -js
# docker
docker run -p 4222:4222 nats:latest -jsThen:
./gradlew :rqueue-spring-boot-nats-example:bootRunOnce the app is up:
# enqueue a String to a queue (default queue is "simple-queue", from application.properties)
curl 'http://localhost:8080/push?q=simple-queue&msg=hello'
# enqueue a Job object to job-queue (with DLQ wired to job-morgue)
curl http://localhost:8080/jobWatch the logs for simple: hello / job-queue: Job(id=…) from MessageListener.
nats stream ls will show:
rqueue-js-simple-queue
rqueue-js-job-queue
rqueue-js-job-queue-dlq
rqueue-js-job-morgue
(The rqueue-js- prefix is the default; configure via rqueue.nats.naming.streamPrefix.)
nats kv ls will show the six shared KV buckets used by the NATS-backed daos
(rqueue-jobs, rqueue-locks, rqueue-message-metadata, etc.). See the README's
"NATS backend" section in the repo root for the full table.
If your NATS account can't run add_stream / kv_create at runtime, set:
rqueue.nats.auto-create-streams=false
rqueue.nats.auto-create-consumers=false
rqueue.nats.auto-create-dlq-stream=false
rqueue.nats.auto-create-kv-buckets=false…and pre-create the streams + buckets per the root README. NatsStreamValidator /
NatsKvBucketValidator will fail boot deterministically with the list of missing
streams / buckets if any are not present.