BullMQ Proxy
  • What is BullMQ Proxy
  • Getting started
    • Architecture overview
    • Using Dragonfly
  • HTTP API
    • Authentication
    • Queues
      • Adding jobs
        • Retries
        • Delayed jobs
        • Prioritized
        • Repeatable
        • LIFO
        • Custom Job IDs
      • Getting jobs
      • Queue's actions
      • Reference
    • Workers
      • Endpoints
      • Adding workers
        • Concurrency
        • Rate-Limit
        • Removing finished jobs
        • Stalled jobs
        • Timeouts
      • Removing workers
      • Getting workers
      • Reference
    • Jobs
      • Jobs' actions
        • Update job progress
        • Add job logs
      • Reference
    • Configuration
    • Debugging
Powered by GitBook
On this page
  1. HTTP API
  2. Workers
  3. Adding workers

Rate-Limit

A quite popular feature of BullMQ is the possibility to activate a rate-limit on a queue. This rate-limit guarantees that no more jobs than what the rate-limit defines will ever be processed, in the case of the proxy this means that the calls to the endpoint will always be within the rate-limit.

Lets add the limiter property to our WorkerMetadata interface:

interface WorkerMetadata {
  opts?: {
    limiter?: {
      max: number; // integer representing max number of jobs to process on "duration"
      duration: number: // number of millisecons
    }
    // .. more options
  }
  // .. more options
}

The limiter just takes 2 properties, "max" defines the maximum number of jobs that will be processed during "duration", which is some time span defined in milliseconds. So for example, to limit to 100 jobs per second we could just use this object:

curl --location 'http://localhost:8080/workers' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 1234' \
--data '{
    "queue": "my-test-queue",
    "opts": {
      "concurrency": 300,
      "limiter": {
        "max": 100,
        "duration": 1000
      }
    },
    "endpoint": {
        "url": "http://mydomain.dev",
        "method": "post"
    }
}'
PreviousConcurrencyNextRemoving finished jobs

Last updated 1 year ago