Skip to main content
Version: Next

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-tag header, where production traffic gets higher priority (1) over staging traffic (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)

ParameterExample ValueDescription
namePriorityQueueFlowThe name of the flow, used to identify it in configurations.
filter.urlapi.website.com/*Filters API requests based on the URL pattern.
processors.QueueLimiter.processorQueueDefines the processor responsible for queuing and prioritizing requests.
processors.QueueLimiter.parameters.keyquota_id, ttl_seconds, queue_size, priority_group_by_header, priority_groupsParameters for configuring the queue's quota, TTL, size, and priority logic.
processors.GenerateResponseTooManyRequests.processorGenerateResponseProcessor that handles responses when requests exceed the queue limit.
processors.GenerateResponseTooManyRequests.parameters.keystatus, body, Content-TypeDefines the status code, body, and content type for the "Too many requests" response.

Quota Configuration

/etc/lunar-proxy/quotas/quota.yaml
quota:
- id: MyQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
max: 10
interval: 1
interval_unit: second

Quota Parameters

/etc/lunar-proxy/quotas/quota.yaml

ParameterExample ValueDescription
quota_idMyQuotaThe identifier for the specific quota applied to the flow.
filter.urlapi.website.com/*Filters requests based on the URL for applying the quota.
strategy.fixed_window.max10Maximum number of allowed requests per second.
strategy.fixed_window.interval1Defines the interval length for the quota (in seconds).
strategy.fixed_window.interval_unitsecondThe unit of time for the quota window.
CTRL + M