All Projects → eljam → circuit-breaker

eljam / circuit-breaker

Licence: MIT license
PHP implementation of circuit breaker pattern

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to circuit-breaker

Cockatiel
A resilience and transient-fault-handling library that allows developers to express policies such as Backoff, Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback. Inspired by .NET Polly.
Stars: ✭ 993 (+5741.18%)
Mutual labels:  circuit-breaker
Failsafe Rs
A circuit breaker implementation for rust
Stars: ✭ 118 (+594.12%)
Mutual labels:  circuit-breaker
Circuit Breaker Php
Circuit Breaker Pattern for PHP
Stars: ✭ 202 (+1088.24%)
Mutual labels:  circuit-breaker
Circuit Breaker Monad
Circuit Breaker pattern as a monad
Stars: ✭ 52 (+205.88%)
Mutual labels:  circuit-breaker
Circuit B
A non intrusive circuit breaker for node.js
Stars: ✭ 88 (+417.65%)
Mutual labels:  circuit-breaker
Heimdall
An enhanced HTTP client for Go
Stars: ✭ 2,132 (+12441.18%)
Mutual labels:  circuit-breaker
Breaker
Circuit breaker for HTTP requests in Elixir
Stars: ✭ 30 (+76.47%)
Mutual labels:  circuit-breaker
Uragano
Uragano, A simple, high performance RPC library. Support load balancing, circuit breaker, fallback, caching, intercepting.
Stars: ✭ 28 (+64.71%)
Mutual labels:  circuit-breaker
Gobreaker
Circuit Breaker implemented in Go
Stars: ✭ 1,867 (+10882.35%)
Mutual labels:  circuit-breaker
Go Chassis
a microservice framework for rapid development of micro services in Go with rich eco-system
Stars: ✭ 2,428 (+14182.35%)
Mutual labels:  circuit-breaker
Rezilience
ZIO-native utilities for making resilient distributed systems
Stars: ✭ 60 (+252.94%)
Mutual labels:  circuit-breaker
Polly
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
Stars: ✭ 9,944 (+58394.12%)
Mutual labels:  circuit-breaker
Safely
Safely is a Clojure's circuit-breaker library for handling retries in an elegant declarative way.
Stars: ✭ 152 (+794.12%)
Mutual labels:  circuit-breaker
Recloser
A concurrent circuit breaker implemented with ring buffers
Stars: ✭ 51 (+200%)
Mutual labels:  circuit-breaker
Diehard
Clojure library of flexible retry, circuit breaker and rate limiter
Stars: ✭ 227 (+1235.29%)
Mutual labels:  circuit-breaker
Semian
🐒 Resiliency toolkit for Ruby for failing fast
Stars: ✭ 976 (+5641.18%)
Mutual labels:  circuit-breaker
Circuitbreaker
.NET Circuit Breaker Pattern Frameworks
Stars: ✭ 122 (+617.65%)
Mutual labels:  circuit-breaker
lua-circuit-breaker
Circuit breaker pattern in Lua
Stars: ✭ 28 (+64.71%)
Mutual labels:  circuit-breaker
resiliency
A modern PHP library that allows you to make resilient calls to external services 🔁
Stars: ✭ 79 (+364.71%)
Mutual labels:  circuit-breaker
Tree Gateway
This is a full featured and free API Gateway
Stars: ✭ 160 (+841.18%)
Mutual labels:  circuit-breaker

Circuit Breaker

Circuit breaker is heavily used in microservice architecture to find issues between microservices calls.

The main idea is to protect your code from making unnecessary call if the microservice you call is down.

Features

  • Automatic update. (i.e you don't have to manually add success or failure method like other library)
  • Return result from the protected function
  • Retry timeout
  • Exclude some exceptions from being throwned, return null instead.
  • Multiprocess updates handled with a cache library. Supports all cache provider from (doctrine cache library).
  • Event powered

Build Status Code Quality Code Coverage SensioLabsInsight Latest Unstable Version Latest Stable Version Downloads license

Full Example:

<?php

use Doctrine\Common\Cache\FilesystemCache;
use Eljam\CircuitBreaker\Breaker;
use Eljam\CircuitBreaker\Event\CircuitEvents;
use Symfony\Component\EventDispatcher\Event;

require_once __DIR__.'/vendor/autoload.php';

$fileCache  = new FilesystemCache('./store', 'txt');

//Create a circuit for github api with a file cache and we want to exclude all exception.
$breaker = new Breaker('github_api', ['ignore_exceptions' => true], $fileCache);

$breaker->addListener(CircuitEvents::SUCCESS, function (Event $event) {
    $circuit = $event->getCircuit();
    echo "Success:".$circuit->getFailures()."\n";
});

$breaker->addListener(CircuitEvents::FAILURE, function (Event $event) {
    $circuit = $event->getCircuit();
    echo "Increment failure:".$circuit->getFailures()."\n";
});

$breaker->addListener(CircuitEvents::OPEN, function (Event $event) {
    $circuit = $event->getCircuit();
    echo sprintf("circuit %s is open \n", $circuit->getName());
});

$breaker->addListener(CircuitEvents::CLOSED, function (Event $event) {
    $circuit = $event->getCircuit();
    echo sprintf("circuit %s is closed \n", $circuit->getName());
});

$breaker->addListener(CircuitEvents::HALF_OPEN, function (Event $event) {
    $circuit = $event->getCircuit();
    echo sprintf("circuit %s is half-open \n", $circuit->getName());
});

$result = $breaker->protect(function () {
    throw new \Exception("An error as occured");
    // return 'ok';
});
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].