Skip to main content
Bull can be used for persistent message queues. This is a quite useful feature in some use cases. For example, you can have two servers that need to communicate with each other. By using a queue the servers do not need to be online at the same time, so this creates a very robust communication channel. You can treat add as send and process as receive.

Implementation

const Queue = require('bull');

const sendQueue = new Queue('Server B');
const receiveQueue = new Queue('Server A');

receiveQueue.process(function (job, done) {
  console.log('Received message', job.data.msg);
  done();
});

sendQueue.add({ msg: 'Hello' });

How It Works

1

Server A sends a message

Server A adds a job to the “Server B” queue with the message “Hello”
2

Server B receives the message

Server B processes jobs from its receive queue and logs the message
3

Server B sends a response

Server B can send messages back to Server A using the same pattern

Benefits

Asynchronous Communication

Servers don’t need to be online simultaneously

Reliable Delivery

Messages are persisted in Redis until processed

Fault Tolerance

Failed messages can be automatically retried

Simple API

Use familiar add() and process() methods

Build docs developers (and LLMs) love