BullMQ
Search…
Message queue
Bull can also 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:
Server A:
1
const Queue = require('bull');
2
3
const sendQueue = new Queue('Server B');
4
const receiveQueue = new Queue('Server A');
5
6
receiveQueue.process(function (job, done) {
7
console.log('Received message', job.data.msg);
8
done();
9
});
10
11
sendQueue.add({ msg: 'Hello' });
Copied!
Server B:
1
const Queue = require('bull');
2
3
const sendQueue = new Queue('Server A');
4
const receiveQueue = new Queue('Server B');
5
6
receiveQueue.process(function (job, done) {
7
console.log('Received message', job.data.msg);
8
done();
9
});
10
11
sendQueue.add({ msg: 'World' });
Copied!
Copy link