Strapi Plugin BullMQ is a plugin that integrates BullMQ with Strapi, providing robust job queue management capabilities for your Strapi applications.
- 📋 Queue Management: Effortlessly create and manage multiple BullMQ queues with a simple API.
- ⚙️ Worker Creation: Set up workers to process jobs from queues seamlessly.
- 🔗 Redis Integration: Utilizes the
@strapi-community/plugin-redisplugin for reliable Redis connections. - 🔧 Job Options: Configure delays, priorities, retry attempts, and more for jobs.
- 🎛️ Worker Options: Control concurrency, rate limiting, and worker behaviors.
- 🧹 Automatic Cleanup: Handles connection cleanup automatically on Strapi shutdown.
- 📝 TypeScript Support: Fully typed for an enhanced development experience.
- Strapi v5
- @strapi-community/plugin-redis
- Install the required Redis plugin & BullMQ plugin:
npm install @strapi-community/plugin-redis strapi-plugin-bullmqor
yarn add @strapi-community/plugin-redis strapi-plugin-bullmqor
pnpm add @strapi-community/plugin-redis strapi-plugin-bullmqFor more details, see: https://strapi-community.github.io/plugin-redis
- Configure the Redis connection for BullMQ in your
config/plugins.jsorconfig/plugins.ts:
module.exports = {
// ...
redis: {
enabled: true,
config: {
connections: {
// ...
queue: {
connection: {
host: env('REDIS_HOST', '127.0.0.1'),
port: env('REDIS_PORT', 6379),
password: env('REDIS_PASSWORD'),
username: env('REDIS_USERNAME', 'default'),
maxRetriesPerRequest: null,
},
},
},
},
},
// ...
};Note: maxRetriesPerRequest must be set to null for persistent connections.
For more details, see: https://docs.bullmq.io/bull/patterns/persistent-connections
- Configure the plugin in your
config/plugins.jsorconfig/plugins.ts:
module.exports = {
// ...
bullmq: {
enabled: true,
config: {
connectionName: 'queue', // Name of the Redis connection to use
},
},
// ...
};Note: connectionName must be the same as the name of the Redis connection configured in the previous step.
const queue = strapi.plugin('bullmq').service('queue').get('my-queue');await queue.add('job-name', { data: 'some data' });const worker = strapi
.plugin('bullmq')
.service('worker')
.create(queue, async (job) => {
console.log('Processing job:', job.name, job.data);
// Process the job
});Recommendation: It is recommended to create and start workers in your bootstrap.ts or bootstrap.js file to ensure they are initialized when the Strapi application starts.
Note: The plugin automatically handles connection cleanup when the Strapi destroy event is fired, so manual cleanup is not required.
You can pass options when adding jobs:
await queue.add(
'job-name',
{ data: 'some data' },
{
delay: 5000, // Delay in milliseconds
priority: 1, // Priority (higher numbers have higher priority)
attempts: 3, // Number of attempts
}
);For more details, see: https://docs.bullmq.io/guide/queues
const worker = strapi
.plugin('bullmq')
.service('worker')
.create(queue, handler, {
concurrency: 5, // Number of concurrent jobs
limiter: { max: 10, duration: 1000 }, // Rate limiting
});For more details, see: https://docs.bullmq.io/guide/workers
We welcome contributions! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure your PR:
- Follows the existing code style
- Includes appropriate tests
- Updates documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- GitHub Issues: Create an issue
- Email: [email protected]