BullMQ is a powerful and versatile job queue library for Node.js. It's based on Redis, which means it can handle heavy loads and is well-suited for production environments. Here are some key points to consider when using BullMQ in a production setting:
const client = new Queue('my-queue', { connection: { host: '127.0.0.1', port: 6379, // Custom retry strategy retryStrategy: function(times) { return Math.min(times * 50, 2000); } } });
await myQueue.add('high priority job', {foo: 'bar'}, {priority: 1}); await myQueue.add('low priority job', {baz: 'qux'}, {priority: 3});
const emailQueue = new Queue('email', { limiter: { max: 100, // Max 100 jobs per interval duration: 60000 // Every minute } });
myQueue.on('completed', (job, result) => { console.log(`Job ${job.id} completed with result: ${result}`); });
// Job level myQueue.process(async (job) => { try { // Process job here } catch (error) { console.error(`Job failed with error: ${error}`); throw error; } }); // Queue level myQueue.on('failed', (job, err) => { console.log(`Job ${job.id} failed with error: ${err.message}`); });
Remember to always thoroughly test your queue logic before deploying it into production to ensure it behaves as expected under different edge cases.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.