Skip to content

Strapi Plugin BullMQ is a plugin that integrates Bull Queue with Strapi, providing robust job queue management capabilities for your Strapi applications.

License

Notifications You must be signed in to change notification settings

revolabs-io/strapi-plugin-bullmq

Repository files navigation

strapi-plugin-bullmq

Strapi Plugin BullMQ is a plugin that integrates BullMQ with Strapi, providing robust job queue management capabilities for your Strapi applications.

✨ Key Features

  • 📋 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-redis plugin 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.

✅ Requirements

  • Strapi v5
  • @strapi-community/plugin-redis

🔧 Installation

  1. Install the required Redis plugin & BullMQ plugin:
npm install @strapi-community/plugin-redis strapi-plugin-bullmq

or

yarn add @strapi-community/plugin-redis strapi-plugin-bullmq

or

pnpm add @strapi-community/plugin-redis strapi-plugin-bullmq

For more details, see: https://strapi-community.github.io/plugin-redis

  1. Configure the Redis connection for BullMQ in your config/plugins.js or config/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

  1. Configure the plugin in your config/plugins.js or config/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:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

🔗 External Links

About

Strapi Plugin BullMQ is a plugin that integrates Bull Queue with Strapi, providing robust job queue management capabilities for your Strapi applications.

Topics

Resources

License

Stars

Watchers

Forks