Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rqueue

> 后端框架
Open source

Rqueue: Job Queue and Scheduler for Spring and Spring Boot (Redis & NATS)

389 stars0 likes1 views
WebsiteGitHub

About

Rqueue: Job Queue and Scheduler for Spring and 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.

Features

  • Job execution

    • Run background jobs asynchronously
    • Schedule jobs for any future time
    • Run periodic jobs at fixed intervals
    • Guarantee at-least-once delivery
    • Retry failed jobs automatically with fixed or exponential backoff
  • Queues and routing

    • Deduplicate messages using message IDs
    • Process priority workloads such as high, medium, and low
    • Prioritize workloads with group-level queue priority and weighted, strict, or hard strict ordering
    • Fan out the same message to multiple listeners
    • Poll messages in batches for higher throughput
  • Consumers and scale

    • Use annotation-driven listeners with Spring beans
    • Get started with just the dependency in Spring Boot applications
    • Run multiple competing consumers in parallel
    • Configure listener concurrency per worker
    • Support long-running jobs with periodic check-ins
    • Serialize and deserialize message payloads automatically
  • Operations and extensibility

    • Add middleware before listener execution
    • Use callbacks for dead-letter, discard, and related flows
    • Subscribe to bootstrap and task execution events
    • Monitor in-flight, queued, and scheduled messages with metrics
    • Use the built-in web dashboard for queue visibility and latency insights
  • Backend and platform support

    • Switch backends with a single property (rqueue.backend=redis|nats)
    • Use a separate Redis setup for Rqueue if needed
    • Support Redis standalone, Sentinel, and Cluster setups
    • Work with Lettuce for Redis Cluster
    • Support reactive Redis and Spring WebFlux
    • Use NATS JetStream as a drop-in Redis replacement (add rqueue-nats and set rqueue.backend=nats)

Requirements

  • Spring 5+, 6+, 7+
  • Java 1.8+, 17, 21
  • Spring Boot 2+, 3+, 4+
  • Redis backend (default): Lettuce client; read-master preference for Redis Cluster
  • NATS backend: NATS Server 2.2+ with JetStream enabled (nats-server -js); rqueue-nats on the classpath

Getting Started

Dependency

Release Version: Maven central

Spring Boot

NOTE:

  • For Spring Boot 3.x use Rqueue 3.x
  • For Spring Boot 4.x use Rqueue 4.x

Get the latest one from Maven central

  • Add dependency

    • Gradle
      groovy
          implementation 'com.github.sonus21:rqueue-spring-boot-starter:4.0.0-RELEASE'
    • Maven
      xml
       
          com.github.sonus21
          rqueue-spring-boot-starter
          4.0.0-RELEASE
      

    No additional configurations are required, only dependency is required.

Spring Boot with NATS backend

To use NATS JetStream instead of Redis, add rqueue-nats alongside the starter and set rqueue.backend=nats in application.properties:

  • Gradle
    groovy
    implementation 'com.github.sonus21:rqueue-spring-boot-starter:4.0.0-RELEASE'
    implementation 'com.github.sonus21:rqueue-nats:4.0.0-RELEASE'
  • Maven
    xml
    
        com.github.sonus21
        rqueue-spring-boot-starter
        4.0.0-RELEASE
    
    
        com.github.sonus21
        rqueue-nats
        4.0.0-RELEASE
    

Then in application.properties:

properties
rqueue.backend=nats
rqueue.nats.connection.url=nats://localhost:4222

No 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.


Spring Framework

NOTE

  • For Spring Framework 6.x use Rqueue 3.x
  • For Spring Framework 7.x use Rqueue 4.x

Get the latest one from Maven central

  • Add Dependency
    • Gradle
      groovy
          implementation 'com.github.sonus21:rqueue-spring:4.0.0-RELEASE'
    • Maven
      xml
       
         com.github.sonus21
         rqueue-spring
         4.0.0-RELEASE
       
  • Add annotation EnableRqueue on application config class
  • Provide a RedisConnectionFactory bean
Configuration
java

@EnableRqueue
public class Application {
  @Bean
  public RedisConnectionFactory redisConnectionFactory() {
    // return a redis connection factory
  }
}

Message publishing/Task submission

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.

…

Worker/Consumer/Task Executor/Listener

Any method that's part of spring bean, can be marked as worker/message listener using RqueueListener annotation

…

Dashboard

Link: http://localhost:8080/rqueue

Queue Statistics

Micrometer based dashboard for queue

Message Waiting For Execution

Recent jobs details


NATS backend

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.

Streams per queue

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.*.

Pre-creating streams (restricted JetStream accounts)

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:

bash
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.

KV buckets (one set, shared across all queues)

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· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaasynchronous-tasksdelayed-jobsdelayed-queuejava

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架