KioMQ provides the core building blocks to run background work inside your Tokio services:
- A [
Queue] to enqueue tasks/jobs. - One or more Workers to process jobs concurrently.
- Pluggable Stores: [
InMemoryStore] (ephemeral), [RedisStore] (durable, distributed),RocksDB(under construction). - Scheduling – delays, cron expressions, repeat policies.
- Reliability – retries, backoff strategies, stalled-job detection.
- Observability – events, progress updates, per-worker & per-process metrics.
Inspired by BullMQ's ergonomics, implemented as an embeddable Rust library.
Contents: Key features · Tokio runtime · Installation · Quick-start · Panics & errors · Configuration · Events & observability · Progress updates · Process & worker metrics · Backends · Benchmarks · Testing · License
Key features
- Async & sync processors – async for I/O-bound work, sync
spawn_blockingfor CPU-bound. - Configurable concurrency – defaults to CPU count.
- Event-driven idle workers – near-zero CPU when empty, using lock-free atomics and
Notify. - Bulk enqueue – [
Queue::bulk_add] / [Queue::bulk_add_only]. - Priority & delayed jobs – by score or after N ms / cron schedule.
- Repeat policies – cron, backoff-driven, fixed interval, immediate.
Tokio runtime requirements
Multi-thread runtime is recommended:
= { = "1", = ["rt-multi-thread", "macros"] }
For tests:
async
Installation
[]
= "0.2.1"
Cargo features: redis-store (default), rocksdb-store, tracing.
Quick-start
Async worker
use Arc;
use ;
async
Sync worker
Sync processors run on a blocking thread via tokio::task::spawn_blocking — suitable for
heavy computation, hashing, blocking FFI, etc.
use Arc;
use ;
async
Panics & errors in the processor
A processor signals a job failure by returning Err. The worker catches the error,
marks the job as failed, and — depending on the attempts configuration — retries it
with the configured backoff.
Panics inside a processor are also caught by the worker and treated as failures, so a rogue job cannot bring down the whole process.
Async backtrace with #[framed]
Annotate your processor with [framed] (re-exported from
async_backtrace as kiomq::framed) for richer async
stack traces:
use Arc;
use ;
async
async
Configuration
Queue options ([QueueOpts])
use ;
let queue_opts = QueueOpts ;
Per-job options ([JobOptions])
use JobOptions;
let opts = JobOptions ;
Worker options ([WorkerOpts])
use WorkerOpts;
let opts = WorkerOpts ;
Events & observability
Subscribe to job-state events on the queue:
use ;
// Subscribe to a specific state.
let _listener_id = queue.on;
// Subscribe to all events.
let _listener_id2 = queue.on_all_events;
// Remove a listener when no longer needed.
queue.remove_event_listener;
Progress updates
Report progress from inside your processor using Job.update_progress:
use Arc;
use ;
async
Process & worker metrics
KioMQ automatically collects two kinds of metrics in the background — no extra setup required.
Process metrics ([ProcessMetrics])
A process-level snapshot refreshed at a regular interval (PROCESS_METRIC_UPDATE_INTERVAL) and
stored in the queue's store with a TTL. Each snapshot captures:
process_cpu_usage– CPU usage of the process tree (%)memory_usage– RSS memory in bytesmemory_stats– heap allocator statistics via the built-inHeapsterinstrumented allocatorrt_metrics– Tokio runtime counters: thread count, live tasks, park counts, busy durations ([RawRuntimeMetrics])workers–Vec<WorkerMeta>with the state, options, and active-job count of every registered workerhostname/pid– process identity
// keyed by PID so multi-process deployments can be distinguished
let snapshots: BTreeMap =
queue.fetch_proess_metrics.await?;
if let Some = snapshots.values.next
Worker metrics ([WorkerMetrics])
Fine-grained, per-worker timing data for every in-flight job — useful for latency profiling and capacity planning:
let worker_metrics = queue.fetch_worker_metrics.await?;
for in &worker_metrics
Both are stored with a TTL and refreshed automatically by the queue's timer subsystem.
Backends
In-memory
[InMemoryStore] – ideal for tests, dev, and short-lived tasks. No external dependencies.
Redis (default feature)
Durable, distributed workloads. Requires a running Redis instance:
use ;
async
RocksDB (under construction)
Embedded persistence – work in progress.
[]
= { default-features=false, features=["rocksdb-store"] }
use ;
use Arc;
async
Benchmarks
Testing
License
MIT — see LICENSE