Liking cljdoc? Tell your friends :D

s-exp.flux.ring

Ring middleware for concurrency limiting.

Usage:

(require '[s-exp.flux :as flux] '[s-exp.flux.ring :as flux.ring])

(def limiter (flux/simple-limiter (flux/vegas-limit {:max-concurrency 200})))

(def app (-> handler (flux.ring/wrap-concurrency-limit limiter)))

By default:

  • The context passed to the limiter is the Ring request map.
  • A 503 response is returned when the limit is exceeded.
  • 5xx responses (except 503 from the app itself) signal a drop.
  • All other responses signal success.

These behaviours are customisable via options.

Ring middleware for concurrency limiting.

Usage:

  (require '[s-exp.flux :as flux]
           '[s-exp.flux.ring :as flux.ring])

  (def limiter
    (flux/simple-limiter (flux/vegas-limit {:max-concurrency 200})))

  (def app
    (-> handler
        (flux.ring/wrap-concurrency-limit limiter)))

By default:
- The context passed to the limiter is the Ring request map.
- A 503 response is returned when the limit is exceeded.
- 5xx responses (except 503 from the app itself) signal a drop.
- All other responses signal success.

These behaviours are customisable via options.
raw docstring

wrap-concurrency-limitclj

(wrap-concurrency-limit handler limiter)
(wrap-concurrency-limit handler
                        limiter
                        {:keys [context-fn on-reject classify on-error]
                         :or {context-fn identity
                              on-reject (constantly default-reject-response)
                              classify default-classify}})

Ring middleware that enforces a concurrency limit.

limiter - a SimpleLimiter (or any com.netflix.concurrency.limits.Limiter)

Options: :context-fn (fn [request] -> context) Builds the limiter context from the Ring request. Defaults to the request map itself.

:on-reject (fn [request] -> response) Called when the limit is exceeded. Defaults to a 503 response.

:classify (fn [response] -> :success | :ignore | :dropped) Maps the Ring response to a limiter signal. Defaults to treating 5xx as :dropped, rest as :success.

:on-error (fn [request throwable] -> response | nil) Called when the handler throws. If it returns a response, that response is returned to the caller (the throwable is still rethrown if nil is returned). The limiter always receives :dropped on exception. Defaults to nil (exceptions propagate).

Ring middleware that enforces a concurrency limit.

`limiter` - a `SimpleLimiter` (or any `com.netflix.concurrency.limits.Limiter`)

Options:
  :context-fn     (fn [request] -> context)
                  Builds the limiter context from the Ring request.
                  Defaults to the request map itself.

  :on-reject      (fn [request] -> response)
                  Called when the limit is exceeded.
                  Defaults to a 503 response.

  :classify       (fn [response] -> :success | :ignore | :dropped)
                  Maps the Ring response to a limiter signal.
                  Defaults to treating 5xx as :dropped, rest as :success.

  :on-error       (fn [request throwable] -> response | nil)
                  Called when the handler throws. If it returns a response,
                  that response is returned to the caller (the throwable is
                  still rethrown if nil is returned). The limiter always
                  receives :dropped on exception.
                  Defaults to nil (exceptions propagate).
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close