php-circuit-breaker-bundle
, (*1)
Description
Everything is MIT licensed and unsupported unless otherwise stated. Use at your own risk., (*2)
Implement circuit breaker pattern see here http://martinfowler.com/bliki/CircuitBreaker.html., (*3)
You can find explanation in french here https://medium.com/eleven-labs/le-circuit-breaker-k%C3%A9sako-4763e13a4a03, (*4)
How to install ?
Requirements
- >=PHP 7
- use LoggerInterface
- use CacheInterface
composer require lemonde/php-circuit-breaker-bundle:lastest
Add in your AppKernel.php, (*5)
public function registerBundles()
{
$bundles = [
....
new CircuitBreakerBundle\CircuitBreakerBundle(),
];
return $bundles;
}
Add in your config.yml, (*6)
circuit_breaker:
# Number fail possible in circuit breaker
threshold: 5
# Time in seconds resend call after circuit breaker is open
timeout: 20
And add config to CacheInterface in your config.yml, (*7)
framework:
cache:
app: cache.adapter.filesystem
How to use ?
Before your service's call, (*8)
if ($this->get('circuit.breaker')->isOpen('your-service')) {
// If service is down
}
You need to send status on service to each call, (*9)
// $status is bool
$this->get('dispatcher')->dispatch('circuit.breaker', new CircuitBreakerEvent('your-service', $status));
How to contribute ?
You can add issue, and create pull request. https://github.com/lemonde/php-circuit-breaker-bundle/blob/master/.github/CONTRIBUTING.md, (*10)