All Projects → sunng87 → Diehard

sunng87 / Diehard

Licence: epl-1.0
Clojure library of flexible retry, circuit breaker and rate limiter

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Diehard

Nestjs Rate Limiter
Highly configurable rate limiter library built for NestJS
Stars: ✭ 93 (-59.03%)
Mutual labels:  rate-limiter
Curiefense
Curiefense is a unified, open source platform protecting cloud native applications.
Stars: ✭ 136 (-40.09%)
Mutual labels:  rate-limiter
Graphql Rate Limit
🚦 Fixed window rate limiting middleware for GraphQL. Use to limit repeated requests to queries and mutations.
Stars: ✭ 171 (-24.67%)
Mutual labels:  rate-limiter
Nginx Lua Redis Rate Measuring
A lua library to provide distributed rate measurement using nginx + redis, you can use it to do a throttling system within many nodes.
Stars: ✭ 109 (-51.98%)
Mutual labels:  rate-limiter
Circuitbreaker
.NET Circuit Breaker Pattern Frameworks
Stars: ✭ 122 (-46.26%)
Mutual labels:  circuit-breaker
Heimdall
An enhanced HTTP client for Go
Stars: ✭ 2,132 (+839.21%)
Mutual labels:  circuit-breaker
Node Fast Ratelimit
☔️ Fast and efficient in-memory rate-limit for Node, used to alleviate most common DOS attacks.
Stars: ✭ 84 (-63%)
Mutual labels:  rate-limiter
Circuit Breaker Php
Circuit Breaker Pattern for PHP
Stars: ✭ 202 (-11.01%)
Mutual labels:  circuit-breaker
Bull
Premium Queue package for handling distributed jobs and messages in NodeJS.
Stars: ✭ 11,748 (+5075.33%)
Mutual labels:  rate-limiter
Tree Gateway
This is a full featured and free API Gateway
Stars: ✭ 160 (-29.52%)
Mutual labels:  circuit-breaker
Gobreaker
Circuit Breaker implemented in Go
Stars: ✭ 1,867 (+722.47%)
Mutual labels:  circuit-breaker
Guzzle Advanced Throttle
A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get the response from cache when the rate limit is exceeded or always get a cached value to spare your rate limits. Using wildcards in host names is also supported.
Stars: ✭ 120 (-47.14%)
Mutual labels:  rate-limiter
Safely
Safely is a Clojure's circuit-breaker library for handling retries in an elegant declarative way.
Stars: ✭ 152 (-33.04%)
Mutual labels:  circuit-breaker
Limiter
一个注解使你的SpringBoot项目获得分布式锁和限流器能力
Stars: ✭ 93 (-59.03%)
Mutual labels:  rate-limiter
Slowapi
A rate limiter for Starlette and FastAPI
Stars: ✭ 169 (-25.55%)
Mutual labels:  rate-limiter
Circuit B
A non intrusive circuit breaker for node.js
Stars: ✭ 88 (-61.23%)
Mutual labels:  circuit-breaker
Throttler
A rate limiting module for NestJS to work with Fastify, Express, GQL, Websockets, and RPC 🧭
Stars: ✭ 145 (-36.12%)
Mutual labels:  rate-limiter
Limitrr
Light NodeJS rate limiting and response delaying using Redis - including Express middleware.
Stars: ✭ 203 (-10.57%)
Mutual labels:  rate-limiter
Go Chassis
a microservice framework for rapid development of micro services in Go with rich eco-system
Stars: ✭ 2,428 (+969.6%)
Mutual labels:  circuit-breaker
Portara
Portara directive is a rate limiter / throttler for GraphQL
Stars: ✭ 158 (-30.4%)
Mutual labels:  rate-limiter

diehard

Build Status Clojars license Donate

Clojure library to provide safety guard to your application. Some of the functionality is wrapper over Failsafe.

Note that from 0.7 diehard uses Clojure 1.9 and spec.alpha for configuration validation. Clojure 1.8 users could stick with diehard 0.6.0.

Usage

A quick example for diehard usage.

Retry block

A retry block will re-execute inner forms when retry criteria matches.

(require '[diehard.core :as dh])
(dh/with-retry {:retry-on TimeoutException
                :max-retries 3}
  (fetch-data-from-the-moon))

Circuit breaker

A circuit breaker will track the execution of inner block and skip execution if the open condition triggered.

(require '[diehard.core :as dh])

(defcircuitbreaker my-cb {:failure-threshold-ratio [8 10]
                          :delay-ms 1000})

(dh/with-circuit-breaker my-cb
  (fetch-data-from-the-moon))

Rate limiter

A rate limiter protects your code block to run limited times per second. It will block or throw exception depends on your configuration.

(require '[diehard.core :as dh])

(defratelimiter my-rl {:rate 100})

(dh/with-rate-limiter my-rl
  (send-people-to-the-moon))

Bulkhead

Bulkhead allows you to limit concurrent execution on a code block.

(require '[diehard.core :as dh])

;; at most 10 threads can run the code block concurrently
(defbulkhead my-bh {:concurrency 10})

(dh/with-bulkhead my-bh
  (send-people-to-the-moon))

Timeout

Timeouts allow you to fail an execution with TimeoutExceededException if it takes too long to complete

(require '[diehard.core :as dh])

(with-timeout {:timeout-ms 5000}
  (fly-me-to-the-moon))

Examples

Retry block

(dh/with-retry {:retry-on          Exception
                :max-retries       3
                :on-retry          (fn [val ex] (prn "retrying..."))
                :on-failure        (fn [_ _] (prn "failed..."))
                :on-failed-attempt (fn [_ _] (prn "failed attempt"))
                :on-success        (fn [_] (prn "did it! success!"))}
               (throw (ex-info "not good" {:not "good"})))

output:

"failed attempt"
"retrying..."
"failed attempt"
"retrying..."
"failed attempt"
"retrying..."
"failed attempt"
"failed..."
Execution error (ExceptionInfo) at main.user$eval27430$reify__27441/get (form-init6791465293873302710.clj:7).
not good

Docs

More options can be found in the documentation from cljdoc.

License

Copyright © 2016-2019 Ning Sun

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Donation

I'm now accepting donation on liberapay, if you find my work helpful and want to keep it going.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].