Strapi Plugin BullMQ is a plugin that integrates BullMQ with Strapi, providing robust job queue management capabilities for your Strapi applications
npm install strapi-plugin-bullmqStrapi Plugin BullMQ is a plugin that integrates BullMQ with Strapi, providing robust job queue management capabilities for your Strapi applications.
- Strapi v5
- @strapi-community/plugin-redis
1. Install the required Redis plugin & BullMQ plugin:
``bash`
npm install @strapi-community/plugin-redis strapi-plugin-bullmq
or
`bash`
yarn add @strapi-community/plugin-redis strapi-plugin-bullmq
or
`bash`
pnpm add @strapi-community/plugin-redis strapi-plugin-bullmq
For more details, see: https://strapi-community.github.io/plugin-redis
2. Configure the Redis connection for BullMQ in your config/plugins.js or config/plugins.ts:
`javascript`
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
3. Configure the plugin in your config/plugins.js or config/plugins.ts:
`javascript`
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.
`javascript`
const queue = strapi.plugin('bullmq').service('queue').get('my-queue');
`javascript`
await queue.add('job-name', { data: 'some data' });
`javascript`
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:
`javascript`
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
`javascript`
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:
1. Fork the repository
2. Create your feature branch (git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature'
3. Commit your changes ()git push origin feature/amazing-feature`)
4. Push to the branch (
5. 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: info@revolabs.io
- Strapi Community Redis Plugin
- BullMQ Documentation
- Strapi Documentation