Background jobs for .NET
The official .NET port of BullMQ. It runs the same scripts as the other libraries on Redis or PostgreSQL, and works with the queues your Node.js services use.
dotnet add package BullMQ
.NET 8.0+ ยท Redis 6.2+ (or Valkey/Dragonfly) or PostgreSQL 13+
Your first queue and worker
using BullMQ;
await using var queue = new Queue("emails", new QueueOptions
{
Connection = ConnectionOptions.FromString("localhost:6379"),
});
await queue.AddAsync("welcome", new { to = "user@example.com" });using BullMQ;
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}'");More .NET examples
Common BullMQ features, written in .NET.
PostgreSQL backend
using BullMQ;
using BullMQ.Postgres;
var pg = new PostgresOptions
{
ConnectionString = "Host=localhost;Database=bullmq;Username=postgres;Password=secret",
};
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 });Shared connection
var mux = await StackExchange.Redis.ConnectionMultiplexer
.ConnectAsync("localhost:6379");
var options = new QueueOptions
{
Connection = new ConnectionOptions { Multiplexer = mux },
};Using BullMQ with .NET
ASP.NET
Host workers in a BackgroundService and share one IConnectionMultiplexer across your queues and workers.
Redis or PostgreSQL
Queue, Worker and Job have the same API on both backends. Set Postgres in the options to use PostgreSQL.
Flows, events and schedules
FlowProducer, QueueEvents and JobScheduler are available, and a shared conformance test suite runs against both backends.
One queue, any language
Jobs added with the Node.js library can be processed by a .NET worker, and the other way around.
What's available in .NET
- Add jobs to queues Supported
- Process jobs (workers) Supported
- Delayed jobs Supported
- Repeatable / scheduled jobs Supported
- Job priorities Supported
- Rate limiting Supported
- Retries & backoff Supported
- Flows (parent / child) Supported
- Job events Supported
- Redis backend Supported
- PostgreSQL backend Supported
- BullMQ Pro Coming soon
BullMQ Pro for .NET Coming soon
BullMQ Pro adds groups, observables and batches to the open source library. It is available for Node.js and Bun today, and support for .NET is on the way.