lukaszaleckas/laravel-circuit-breaker is a Laravel package.
It currently has 0 GitHub stars and 0 downloads on Packagist.
Install it with composer require lukaszaleckas/laravel-circuit-breaker.
Discover more Laravel packages by lukaszaleckas
or browse all Laravel packages to compare alternatives.
Last updated
Circuit breaker is a design pattern used in software development. It is used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties.
Source: Wikipedia
Let's explain what this does using an example, as they are much better than definitions, in my opinion.
Let's say you have two microservices A and B:
B from A and have a 30s timeout configured.B fails to respond and you receive a timeout error.A and keep failing with a timeout from B.A gets filled up.A start to timeout.In this case it would be much better to track request failures
from A to B and return an error immediately.
Circuit Breaker pattern does just that - on A you are tracking
request failures to B and if failure count, in the particular
time window, exceeds threshold, you skip doing those requests
and return an error immediately.
composer require lukaszaleckas/laravel-circuit-breaker
Service provider should be automatically registered, if not add
LaravelCircuitBreaker\CircuitBreakerServiceProvider::class
to your application's app.php.
circuit-breaker.php config file: php artisan vendor:publish --tag=circuit-breaker
Inject LaravelCircuitBreaker\CircuitBreakerService through constructor.
Use getCircuitBreaker with service name passed as a parameter
to get a circuit breaker instance.
Method usage:
isClosed in your, for example, HTTP client to determine
if requests can be made.registerFailure when you receive an error.registerSuccess when you receive a success response.
This is used to close the circuit when/if it's half open.