Rqueue: 适用于 Spring 和 Spring Boot 的作业队列和调度程序 (Redis 和 NATS)
Rqueue is a job queue and producer-consumer system for Spring and Spring Boot with pluggable broker backends — Redis (default) and NATS JetStream. It supports producers and consumers for background jobs, scheduled tasks, and event-driven workflows, similar to Sidekiq or Celery, fully integrated into the Spring programming model with annotation-driven APIs and minimal setup.
Job execution
Queues and routing
Consumers and scale
Operations and extensibility
Backend and platform support
rqueue.backend=redis|nats)rqueue-nats and set rqueue.backend=nats)nats-server -js); rqueue-nats on the classpathRelease Version: Maven central
NOTE:
Get the latest one from Maven central
Add dependency
implementation 'com.github.sonus21:rqueue-spring-boot-starter:4.0.0-RELEASE'
com.github.sonus21
rqueue-spring-boot-starter
4.0.0-RELEASE
No additional configurations are required, only dependency is required.
To use NATS JetStream instead of Redis, add rqueue-nats alongside the starter and set
rqueue.backend=nats in application.properties:
implementation 'com.github.sonus21:rqueue-spring-boot-starter:4.0.0-RELEASE'
implementation 'com.github.sonus21:rqueue-nats:4.0.0-RELEASE'
com.github.sonus21
rqueue-spring-boot-starter
4.0.0-RELEASE
com.github.sonus21
rqueue-nats
4.0.0-RELEASE
Then in application.properties:
rqueue.backend=nats
rqueue.nats.connection.url=nats://localhost:4222No RedisConnectionFactory bean is required. Start a JetStream-enabled NATS server with
nats-server -js and the application is ready. See the NATS backend section
below for streams, KV buckets, and advanced configuration.
NOTE
Get the latest one from Maven central
implementation 'com.github.sonus21:rqueue-spring:4.0.0-RELEASE'
com.github.sonus21
rqueue-spring
4.0.0-RELEASE
EnableRqueue on application config class
@EnableRqueue
public class Application {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
// return a redis connection factory
}
}All messages need to be sent using RqueueMessageEnqueuer bean's enqueueXXX, enqueueInXXX
and enqueueAtXXX methods. It has handful number of enqueue, enqueueIn, enqueueAt methods, we
can use any one of them based on the use case.
…Any method that's part of spring bean, can be marked as worker/message listener
using RqueueListener annotation
…Link: http://localhost:8080/rqueue
Micrometer based dashboard for queue
Rqueue can use NATS JetStream as the message broker instead of Redis by setting
rqueue.backend=nats and including the rqueue-nats module on the classpath. State that Redis
stores in keys, hashes, and sorted-sets is mapped onto JetStream streams (for messages) and
JetStream KV buckets (for everything else). Both are provisioned once at startup —
streams by NatsStreamValidator on RqueueBootstrapEvent, KV buckets by NatsKvBucketValidator
on the Connection bean — so the publish / pop hot path never pays a getStreamInfo round-trip
to confirm the stream exists. As long as the JetStream credentials allow add_stream /
kv_create, nothing needs to be created ahead of time. For locked-down accounts see the
"Pre-creating streams" / "Pre-creating buckets" subsections below.
Each registered queue produces one main stream, one DLQ stream (when
rqueue.nats.autoCreateDlqStream=true, the default), and one extra stream per priority
sub-queue the queue declares. Only the main queue has a DLQ — priority sub-queues fan out to
their own streams but share the parent queue's DLQ wiring through RqueueExecutor.
| Queue shape | Stream count | Names (with default prefixes) |
|---|---|---|
| Plain queue, DLQ on (default) | 2 | rqueue-js-, rqueue-js--dlq |
| Plain queue, DLQ off | 1 | rqueue-js- |
| Queue with N priorities, DLQ on | N + 2 | rqueue-js-, rqueue-js-- … rqueue-js--, rqueue-js--dlq |
The naming scheme is [-][], configurable via
rqueue.nats.naming.streamPrefix (default rqueue-js-) and rqueue.nats.naming.dlqSuffix
(default -dlq). The -js- segment makes Rqueue's message streams easy to distinguish at a
glance from the JetStream-backed KV buckets below (which keep the plain rqueue- prefix because
that's the operator-facing bucket name, not a stream name) and from anything else sharing the
JetStream account. Subjects follow the same shape with . separators:
[.][] (default subject prefix
rqueue.js.). Stream defaults (replicas, storage, retention, duplicate window, max msgs/bytes)
come from rqueue.nats.stream.*.
For deployments where the application credentials cannot run add_stream at runtime, set
rqueue.nats.autoCreateStreams=false and pre-create every stream the application needs.
NatsStreamValidator walks EndpointRegistry on RqueueBootstrapEvent and verifies that
every main stream, every priority sub-queue stream, and every DLQ stream (for queues whose
listener declared a DLQ) exists. If any are missing it aborts boot with one
IllegalStateException listing all of them — operator-actionable failure at startup, not a
"stream not found" on first enqueue.
The streams to pre-create follow the table above. For a queue orders with priorities
high / low and a DLQ:
nats stream add rqueue-js-orders --subjects rqueue.js.orders ...
nats stream add rqueue-js-orders-high --subjects rqueue.js.orders.high ...
nats stream add rqueue-js-orders-low --subjects rqueue.js.orders.low ...
nats stream add rqueue-js-orders-dlq --subjects rqueue.js.orders.dlq ...Consumers (durable pull consumers) are still created lazily — the broker calls
ensureConsumer once per (stream, consumerName) pair on the cold path of the first pop and
caches the bind in-process, so there's no per-pop RTT after warm-up. Set
rqueue.nats.autoCreateConsumers=false to fail-fast on missing consumers instead of creating
them.
State that Redis stores in keys, hashes, and sorted-sets is mapped onto JetStream KV buckets —
one bucket per concern, not per queue (per-queue scoping is done via key prefix). All buckets
use the default replicas / storage settings of the JetStream account unless noted; per-entry TTL
relies on the bucket's ttl (NATS' name for maxAge), which is set once at bucket creation.
| Bucket name | Purpose | TTL behaviour | Created in |
|---|---|---|---|
rqueue-queue-config |
Per-queue QueueConfig records (registered queues, DLQ wiring, flags). |
No TTL. Entries persist until explicitly overwritten. | NatsRqueueSystemConfigDao (@Conditional(NatsBackendCondition)) |
rqueue-jobs |
RqueueJob execution history per message id. |
TTL captured from the first createJob/save call's expiry argument; bucket-level so it applies uniformly. |
NatsRqueueJobDao |
rqueue-locks |
Distributed locks (scheduler leadership, message-level locks). | TTL captured from the first acquireLock call's duration argument. |
NatsRqueueLockManager |
rqueue-message-metadata |
Per-message metadata (delivery status, retry count, dead-letter flags). | No TTL at the bucket. Per-write ttl arguments are ignored on this v1 impl. |
[NatsRqueueMessageMetadataService](rqueue-nats/src/main/java/com/github/sonu |
暂无开放 Issues,或尚未同步最近议题。