BullMQ 1.4.0

dotnet add package BullMQ --version 1.4.0
                    
NuGet\Install-Package BullMQ -Version 1.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BullMQ" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BullMQ" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="BullMQ" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BullMQ --version 1.4.0
                    
#r "nuget: BullMQ, 1.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BullMQ@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BullMQ&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=BullMQ&version=1.4.0
                    
Install as a Cake Tool

BullMQ for .NET

The official .NET port of BullMQ, the fast and robust Redis- and PostgreSQL-based distributed queue.

This binding is glue code on top of the exact same Lua (Redis) and SQL (PostgreSQL) scripts used by every other BullMQ runtime (Node.js, Python, PHP, Elixir, Rust). Sharing the scripts is what guarantees identical, battle-tested atomicity and semantics across languages: a queue produced by the Node.js library can be consumed by a .NET worker and vice versa.

Status: the database-agnostic queue-backend contract is fully implemented for both Redis and PostgreSQL and validated by a shared conformance suite (the exact same tests run against both adapters). The high-level Queue, Worker and Job classes run on either backend — select PostgreSQL by setting Postgres on the options. FlowProducer, QueueEvents and JobScheduler are also implemented.

Requirements

  • .NET 8.0 or newer
  • A Redis 6.2+ server (or a compatible server such as Valkey/Dragonfly), or a PostgreSQL 13+ server when using the PostgreSQL backend

Installation

dotnet add package BullMQ

Quick start

using BullMQ;

// Create a queue and add a job.
await using var queue = new Queue("emails", new QueueOptions
{
    Connection = ConnectionOptions.FromString("localhost:6379"),
});

await queue.AddAsync("welcome", new { to = "user@example.com" });

// Process jobs with a worker.
await using var worker = new Worker("emails", async (job, ct) =>
{
    Console.WriteLine($"Processing {job.Name} #{job.Id}");
    // ... do the work ...
    return "sent";
}, new WorkerOptions
{
    Connection = ConnectionOptions.FromString("localhost:6379"),
    Concurrency = 5,
});

worker.Completed += (job, result) =>
    Console.WriteLine($"Job {job.Id} completed with '{result}'");

Sharing a connection

Pass an existing IConnectionMultiplexer to reuse a connection across queues and workers (BullMQ will not dispose a connection it does not own):

var mux = await StackExchange.Redis.ConnectionMultiplexer.ConnectAsync("localhost:6379");
var options = new QueueOptions
{
    Connection = new ConnectionOptions { Multiplexer = mux },
};

Using PostgreSQL

Set Postgres on the options to run the exact same Queue/Worker/Job API against PostgreSQL instead of Redis. The schema (default bullmq) namespaces all queues and the required tables/functions are migrated automatically on first use.

using BullMQ;
using BullMQ.Postgres;

var pg = new PostgresOptions
{
    ConnectionString = "Host=localhost;Database=bullmq;Username=postgres;Password=postgres",
    // Schema = "bullmq", // optional, this is the default
    // PoolSize = 20,     // optional, max pooled query connections
};

await using var queue = new Queue("emails", new QueueOptions { Postgres = pg });
await queue.AddAsync("welcome", new { to = "user@example.com" });

await using var worker = new Worker("emails", async (job, ct) => "sent",
    new WorkerOptions { Postgres = pg, Concurrency = 5 });

Retrying failed jobs

Set Attempts to retry a job whose processor throws, and optionally a Backoff to wait between attempts. Without Backoff, a failed job is retried immediately. Behaviour is the same on Redis and PostgreSQL.

await queue.AddAsync("send", new { to = "user@example.com" }, new JobsOptions
{
    Attempts = 5,
    // Waits 1s, 2s, 4s, 8s. Jitter (0 to 1) randomizes each delay down to
    // delay * (1 - jitter).
    Backoff = new BackoffOptions { Type = "exponential", Delay = 1000, Jitter = 0.5 },
});
  • fixed: waits Delay ms before every retry.
  • exponential: waits 2^(attemptsMade - 1) * Delay ms.
  • Custom types: set WorkerOptions.BackoffStrategy to compute the delay for any other Type. Return 0 to retry immediately or -1 to fail the job without further retries. An unknown type without a strategy is an error.
var options = new WorkerOptions
{
    Connection = ConnectionOptions.FromString("localhost:6379"),
    BackoffStrategy = (attemptsMade, type, error, job) =>
        Task.FromResult(type == "linear" ? attemptsMade * 1000L : -1L),
};

Throw UnrecoverableException to fail a job immediately, skipping its remaining attempts. WorkerOptions.MaxStartedAttempts limits how many times a job can be started, which also counts starts that stalled. The worker raises Failed for every failed attempt, including attempts that are retried. Each failure updates the job's FailedReason and appends to its StackTrace.

Custom IQueueBackend implementations must accept the optional failedReason and stackTraceJson parameters of MoveToDelayedAsync and RetryJobAsync, and persist them on the job when a retry is scheduled.

Queries run on a connection pool shared by every queue, worker and QueueEvents in the process that uses the same connection string and schema. Size it with PoolSize (default 20) or Maximum Pool Size in the connection string; each worker and QueueEvents also keeps one dedicated LISTEN connection outside the pool, so size the server's max_connections accordingly.

Deduplication

Set JobsOptions.Deduplication to suppress jobs with the same identifier. The same options work with Redis and PostgreSQL, single and bulk adds, and QueueOptions.DefaultJobOptions.

await queue.AddAsync("refresh", new { version = 1 }, new JobsOptions
{
    Delay = 5000,
    Deduplication = new DeduplicationOptions
    {
        Id = "refresh",
        Reschedule = true,
        Ttl = 10000,
        Extend = true,
    },
});
  • Simple: only Id; suppress duplicates until completion or failure.
  • Throttle: set Ttl in milliseconds to suppress duplicates for that window.
  • Extend: refresh the TTL on duplicate adds.
  • Replace: replace the existing delayed job with the incoming ID and payload.
  • Reschedule: retain the delayed job's ID, name and payload, but apply the incoming delay relative to its timestamp. Omitted/zero delay makes it due. Non-delayed jobs are unchanged. TTL extension is independent; Replace takes precedence if both flags are enabled.
  • KeepLastIfActive: retain only the latest successor payload while the winner is active; create it when that winner completes or fails. TTL is ignored and the key stays live for the job lifecycle.

A per-job deduplication object replaces the entire queue-default object. Duplicate adds return the winning ID, but their returned object still describes the incoming payload; use queue.GetJobAsync(id) to inspect stored job data. This matches the reference BullMQ API.

var winner = await queue.GetDeduplicationJobIdAsync("refresh");
await queue.RemoveDeduplicationKeyAsync("refresh"); // Unconditional removal.
if (winner is not null && await queue.GetJobAsync(winner) is { } job)
{
    await job.RemoveDeduplicationKeyAsync(); // Removes only if still the owner.
}

QueueEvents.Deduplicated exposes DeduplicationId, JobId and DeduplicatedJobId. The event is also delivered to EventReceived. Rescheduling additionally emits Delayed; replacement retains the scripts' Removed events.

Flow validation happens before any writes. Deduplication is forbidden on all nodes with children and on every child node, including nested leaves. Deduplication remains supported on standalone roots without children; Replace must be omitted in flows. A dedup winner may belong to another parent, and jobs cannot belong to multiple parents. Standalone root leaves support the other modes, including KeepLastIfActive. This stricter validation applies to the .NET flow API; other ports retain their existing behavior.

Adding deduplication management extends IQueueBackend with winner lookup, unconditional deletion and conditional owner deletion; custom backend implementations must supply these operations.

Removing finished jobs

By default completed and failed jobs are kept. Set JobsOptions.RemoveOnComplete / RemoveOnFail to true (remove), false (keep), a number (keep the latest

  1. or a KeepJobs policy (Age in seconds and/or Count):
await queue.AddAsync("report", data, new JobsOptions
{
    RemoveOnComplete = true,
    RemoveOnFail = new KeepJobs { Age = 24 * 3600, Count = 5000 },
});

A worker can set defaults for jobs that don't define their own. The job's setting, including false, always takes precedence over the worker's:

await using var worker = new Worker("reports", processor, new WorkerOptions
{
    Connection = ConnectionOptions.FromString("localhost:6379"),
    RemoveOnComplete = new KeepJobs { Count = 1000 },
    RemoveOnFail = new KeepJobs { Age = 7 * 24 * 3600 },
});

Retention is applied when a job finishes, so aged jobs are only evicted when a later job of the same kind finishes. Options written by the other BullMQ runtimes (boolean, number or {count, age, limit} object) are honored the same way. KeepJobs.Limit caps how many aged jobs one eviction removes and only applies to Redis.

Flows: child failures and the job tree

A child added with a FlowProducer (or with JobsOptions.Parent on Queue.AddAsync) can decide what happens to its parent when it fails permanently:

  • FailParentOnFailure: the parent fails too (when a worker picks it up).
  • ContinueParentOnFailure: the parent starts processing right away; it can call GetIgnoredChildrenFailuresAsync() and RemoveUnprocessedChildrenAsync().
  • IgnoreDependencyOnFailure: the parent completes as normal; the failure is kept and returned by GetIgnoredChildrenFailuresAsync().
  • RemoveDependencyOnFailure: the child is dropped from the parent's dependencies.
var tree = await flow.AddAsync(new FlowJob
{
    Name = "report",
    QueueName = "reports",
    Children = new[]
    {
        new FlowJob
        {
            Name = "fetch",
            QueueName = "fetchers",
            Opts = new JobsOptions { IgnoreDependencyOnFailure = true },
        },
    },
});

// Later: child key -> failed reason
var ignored = await tree.Job.GetIgnoredChildrenFailuresAsync();

// The job and its children, recursively.
var node = await flow.GetFlowAsync(new GetFlowOptions { Id = tree.Job.Id!, QueueName = "reports" });

GetFlowOptions.Depth (default 10, the root counts as one level) and MaxChildren (default 20 per category) bound the returned tree.

Rate limiting and global concurrency

// At most 10 jobs per second across every worker of the queue.
var worker = new Worker("painter", processor, new WorkerOptions
{
    Connection = connection,
    Limiter = new RateLimiterOptions { Max = 10, Duration = 1000 },
});

// Or set a global rate limit / concurrency on the queue itself.
await queue.SetGlobalRateLimitAsync(10, 1000);
await queue.SetGlobalConcurrencyAsync(4);

To rate limit manually (e.g. after an HTTP 429), call worker.RateLimitAsync(ms) or queue.RateLimitAsync(ms) from the processor and throw RateLimitException. The job goes back to wait without consuming an attempt or raising Failed, and the worker sleeps until the limit lifts.

Custom IQueueBackend implementations must also implement the operations these features add (rate-limit window, moving an active job back to wait, ignored children failures, dependency keys, removing unprocessed children and removing meta fields).

Development

The shared Lua scripts live at the repository root under rawScripts/ and are copied into dotnet/src/BullMQ/Commands/ (embedded into the assembly) and, for the PostgreSQL backend, src/postgres/** is copied into dotnet/src/BullMQ/Postgres/. These copies are generated and git-ignored.

From the repository root:

# Populate the generated script copies (requires `yarn install` once).
yarn copy:lua:dotnet
yarn copy:sql:dotnet

# Build and test.
cd dotnet
dotnet build
dotnet test          # requires a Redis server on localhost:6379

Or just run the helper, which copies the shared scripts if needed, sets the default test connections, and runs the suite (any arguments are passed straight through to dotnet test):

cd dotnet
./scripts/test.sh                      # whole suite (Redis + PostgreSQL)
./scripts/test.sh --filter Name~Flow   # a subset

Set BULLMQ_TEST_REDIS and/or BULLMQ_TEST_POSTGRES to point the integration tests at different servers.

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 58 11/26/2026
1.3.8 83 11/24/2026
1.3.7 110 11/19/2026
1.3.6 92 11/19/2026
1.3.5 94 11/19/2026
1.3.4 98 11/19/2026
1.3.3 94 11/19/2026
1.3.2 272 11/19/2026
1.3.1 117 11/12/2026
1.3.0 140 11/4/2026
1.2.3 133 10/28/2026
1.2.2 266 10/14/2026
1.2.1 146 9/18/2026
1.2.0 125 9/12/2026
1.1.1 144 8/25/2026
1.1.0 501 8/12/2026
1.0.0 882 8/5/2026