strapi-plugin-bullmq
v1.0.1
Published
Strapi Plugin BullMQ is a plugin that integrates BullMQ with Strapi, providing robust job queue management capabilities for your Strapi applications
Readme
strapi-plugin-bullmq
Strapi Plugin BullMQ is a plugin that integrates BullMQ with Strapi, providing robust job queue management capabilities for your Strapi applications.
✅ Requirements
- Strapi v5
- @strapi-community/plugin-redis
🔧 Installation
- 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.
📖 Usage
Creating a Queue
const queue = strapi.plugin('bullmq').service('queue').get('my-queue');Adding Jobs to a Queue
await queue.add('job-name', { data: 'some data' });Creating a Worker
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.
Job Options
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
Worker Options
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
🤝 Contributing
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
� License
This project is licensed under the MIT License - see the LICENSE file for details.
📬 Contact & Support
- GitHub Issues: Create an issue
- Email: [email protected]
