Flow Example
In this configuration:
- API requests to api.website.com/*are queued with a limit of 10 requests per second.
- Requests are prioritized based on the x-lunar-consumer-tagheader, whereproductiontraffic gets higher priority (1) overstagingtraffic (2).
- If the queue is full or a request is delayed beyond the defined TTL (12 seconds), the system returns a 429 HTTP status code with the message: "Too many requests. Please try again later."
Flow Configuration
/etc/lunar-proxy/flows/flow.yaml
name: PriorityQueueFlow
filter:
  url: api.website.com/*
processors:
  QueueLimiter:
    processor: Queue
    parameters:
      - key: quota_id
        value: MyQuota
      - key: ttl_seconds
        value: 12
      - key: queue_size
        value: 10
      - key: priority_group_by_header
        value: x-lunar-consumer-tag
      - key: priority_groups
        value:
          production: 1
          staging: 2
  GenerateResponseTooManyRequests:
    processor: GenerateResponse
    parameters:
      - key: status
        value: 429
      - key: body
        value: "Too many requests. Please try again later."
      - key: Content-Type
        value: text/plain
flow:
  request:
    - from:
        stream:
          name: globalStream
          at: start
      to:
        processor:
          name: QueueLimiter
    - from:
        processor:
          name: QueueLimiter
          condition: blocked
      to:
        processor:
          name: GenerateResponseTooManyRequests
    - from:
        processor:
          name: QueueLimiter
          condition: allowed
      to:
        stream:
          name: globalStream
          at: end
  response:
    - from:
        processor:
          name: GenerateResponseTooManyRequests
      to:
        stream:
          name: globalStream
          at: end
Flow Parameters (flow.yaml)
| Parameter | Example Value | Description | 
|---|---|---|
| name | PriorityQueueFlow | The name of the flow, used to identify it in configurations. | 
| filter.url | api.website.com/* | Filters API requests based on the URL pattern. | 
| processors.QueueLimiter.processor | Queue | Defines the processor responsible for queuing and prioritizing requests. | 
| processors.QueueLimiter.parameters.key | quota_id,ttl_seconds,queue_size,priority_group_by_header,priority_groups | Parameters for configuring the queue's quota, TTL, size, and priority logic. | 
| processors.GenerateResponseTooManyRequests.processor | GenerateResponse | Processor that handles responses when requests exceed the queue limit. | 
| processors.GenerateResponseTooManyRequests.parameters.key | status,body,Content-Type | Defines the status code, body, and content type for the "Too many requests" response. | 
Quota Configuration
/etc/lunar-proxy/quotas/quota.yaml
quotas:
  - id: MyQuota
    filter:
      url: api.website.com/*
    strategy:
      fixed_window:
        static:
          max: 10
          interval: 1
          interval_unit: second
Quota Parameters
/etc/lunar-proxy/quotas/quota.yaml
| Parameter | Example Value | Description | 
|---|---|---|
| quota_id | MyQuota | The identifier for the specific quota applied to the flow. | 
| filter.url | api.website.com/* | Filters requests based on the URL for applying the quota. | 
| strategy.fixed_window.max | 10 | Maximum number of allowed requests per second. | 
| strategy.fixed_window.interval | 1 | Defines the interval length for the quota (in seconds). | 
| strategy.fixed_window.interval_unit | second | The unit of time for the quota window. |