queue is a queue and workflow library with pluggable backends and runtime extensions.
Installation
go get github.com/goforj/queue
Existing deployments upgrading to application-type direct delivery must replace workers before switching producers. Follow the direct delivery migration guide, including its SQL schema step and backend-specific rollback constraints.
Applications upgrading from the retired bus or queuefake packages should follow the legacy API migration guide. The retired Temporal compatibility adapter is replaced by the optional Temporal driver, which has its own explicit configuration and lifecycle contract.
Queue and its driver modules require Go 1.27 or newer. Projects on older Go releases can pin the v0.2 release line. The PostgreSQL driver continues to use pgx 5.9.2 or newer, the first release containing the GO-2026-5004 security fix.
Quick Start
import (
"context"
"fmt"
"github.com/goforj/queue"
)
func main() {
q, _ := queue.NewWorkerpool(
queue.WithWorkers(2), // optional; default: runtime.NumCPU() (min 1)
)
type EmailPayload struct {
To string `json:"to"`
}
q.Register("emails:send", func(ctx context.Context, m queue.Message) error {
var payload EmailPayload
_ = m.Bind(&payload)
fmt.Println("send to", payload.To)
return nil
})
_ = q.StartWorkers(context.Background())
defer q.Shutdown(context.Background())
_, _ = q.Dispatch(
queue.NewJob("emails:send").
Payload(EmailPayload{To: "user@example.com"}),
)
}
Durable named continuations bind registered hook jobs to chains and batches with immutable trigger snapshots and recoverable outcomes.
Drivers
Each driver is thoroughly tested against the shared test suite using testcontainers or emulators where appropriate.
| Driver / Backend |
Mode |
Notes |
Durable |
Async |
Delay |
Unique |
Backoff |
Timeout |
Native Stats |
Queue Admin |
|
Drop-only |
Discards dispatched jobs; useful for disabled queue modes and smoke tests. |
- |
- |
- |
Instance |
- |
- |
- |
- |
|
Inline (caller) |
Deterministic local execution with no external infra. |
- |
- |
- |
Instance |
- |
✓ |
- |
- |
|
In-process pool |
Local async behavior without external broker/database. |
- |
✓ |
✓ |
Instance |
✓ |
✓ |
- |
- |
|
SQL durable queue |
MySQL driver module (driver/mysqlqueue) built on shared SQL queue core. |
✓ |
✓ |
✓ |
Backend |
✓ |
✓ |
✓ |
- |
|
SQL durable queue |
Postgres driver module (driver/postgresqueue) built on shared SQL queue core. |
✓ |
✓ |
✓ |
Backend |
✓ |
✓ |
✓ |
- |
|
SQL durable queue |
SQLite driver module (driver/sqlitequeue) built on shared SQL queue core. |
✓ |
✓ |
✓ |
Backend |
✓ |
✓ |
✓ |
- |
|
Redis/Asynq |
Production Redis backend (Asynq semantics). |
✓ |
✓ |
✓ |
Backend |
- |
✓ |
✓ |
✓ |
|
Ephemeral broker |
Core NATS subject routing; every plain subscription can receive a broadcast copy. |
- |
✓ |
✓ |
Instance |
✓ |
✓ |
- |
- |
|
Broker target |
AWS SQS transport with endpoint overrides for localstack/testing. |
- |
✓ |
✓ |
Instance |
✓ |
✓ |
- |
- |
|
Broker target |
RabbitMQ transport and worker consumption. |
- |
✓ |
✓ |
Instance |
✓ |
✓ |
- |
- |
|
Workflow service |
Optional driver/temporalqueue; portable jobs, chains, batches and native SDK workflows. Configuration and limits. |
✓ |
✓ |
✓ |
Unsupported |
✓ |
✓ |
- |
- |
SQL-backed queues (sqlite, mysql, postgres) are durable and convenient, but they trade throughput for operational simplicity. They default to 1 worker, and increasing concurrency may require DB tuning (indexes, connection pool, lock contention). Prefer broker-backed drivers for higher-throughput workloads.
Unique scope: Instance suppresses duplicates only within one queue runtime instance; Backend shares claims through the configured database or Redis service. Identity is the effective queue, logical application job type, and canonical serialized payload. Absent, zero-byte, and exact JSON null payloads share one absence identity; generated workflow IDs and delivery options do not change it. See docs/backend-guarantees.md for acceptance, rollout, and failure-boundary details.
Queue Admin status: the cross-driver admin contract is defined in core (ListJobs, RetryJob, CancelJob, DeleteJob, ClearQueue, QueueHistory), but full queue admin operations are currently implemented only for Redis. Other drivers return ErrQueueAdminUnsupported for unsupported admin actions.
Driver constructor quick examples
Use root constructors for in-process backends, and driver-module constructors for external backends. See the Driver Constructors API section below for full constructor shapes (New(...) and NewWithConfig(...)).
Driver backends live in separate packages so applications only import/link the optional backend dependencies they actually use (smaller builds, less dependency overhead, cleaner deploys).
package main
import (
"github.com/goforj/queue"
"github.com/goforj/queue/driver/mysqlqueue"
"github.com/goforj/queue/driver/natsqueue"
"github.com/goforj/queue/driver/postgresqueue"
"github.com/goforj/queue/driver/rabbitmqqueue"
"github.com/goforj/queue/driver/redisqueue"
"github.com/goforj/queue/driver/sqlitequeue"
"github.com/goforj/queue/driver/sqsqueue"
)
func main() {
queue.NewSync() // in-process sync
queue.NewWorkerpool() // in-process worker pool
queue.NewNull() // drop-only / disabled mode
sqlitequeue.New("file:queue.db?_busy_timeout=5000") // SQL durable queue (SQLite)
mysqlqueue.New("user:pass@tcp(127.0.0.1:3306)/app") // SQL durable queue (MySQL)
postgresqueue.New("postgres://user:pass@127.0.0.1:5432/app?sslmode=disable") // SQL durable queue (Postgres)
redisqueue.New("127.0.0.1:6379") // Redis/Asynq
natsqueue.New("nats://127.0.0.1:4222") // NATS
sqsqueue.New("us-east-1") // SQS
rabbitmqqueue.New("amqp://guest:guest@127.0.0.1:5672/") // RabbitMQ
}
Quick Start (Advanced: Workflows)
import (
"context"
"github.com/goforj/queue"
)
type EmailPayload struct {
ID int `json:"id"`
}
func main() {
q, _ := queue.NewWorkerpool()
q.Register("reports:generate", func(ctx context.Context, m queue.Message) error {
return nil
})
q.Register("reports:upload", func(ctx context.Context, m queue.Message) error {
var payload EmailPayload
if err := m.Bind(&payload); err != nil {
return err
}
return nil
})
q.Register("users:notify_report_ready", func(ctx context.Context, m queue.Message) error {
return nil
})
_ = q.StartWorkers(context.Background())
defer q.Shutdown(context.Background())
chainID, _ := q.Chain(
// 1) generate report data
queue.NewJob("reports:generate").Payload(map[string]any{"report_id": "rpt_123"}),
// 2) upload report artifact after generate succeeds
queue.NewJob("reports:upload").Payload(EmailPayload{ID: 123}),
// 3) notify user only after upload succeeds
queue.NewJob("users:notify_report_ready").Payload(map[string]any{"user_id": 123}),
).OnQueue("critical").Dispatch(context.Background())
_ = chainID
}
Run as a Worker Service
Use Run(ctx) for long-lived workers: it starts processing, waits for shutdown signals, and performs graceful termination.