Download the PHP package pixelfederation/circuit-breaker-bundle without Composer
On this page you can find all versions of the php package pixelfederation/circuit-breaker-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pixelfederation/circuit-breaker-bundle
More information about pixelfederation/circuit-breaker-bundle
Files in pixelfederation/circuit-breaker-bundle
Package circuit-breaker-bundle
Short Description An analogous bundle to Java's Hystrix in PHP world.
License BSD-3-Clause
Homepage https://github.com
Informations about the package circuit-breaker-bundle
Circuit breaker bundle
This bundle tries to copy the famous java Hystrix library and tries to make the usage of the circuit breaking pattern effortless to the developers.
The developers can just mark any service as circuit broken, using special annotations and this bundle makes all the wiring under the hood automatically.
The current backend implementation is using Ganesha.
Installation
Configuration
Just enable the bundle. There are no configuration options for now.
Usage
To activate circuit breaking on a given service, the service has to implement
the PixelFederation\CircuitBreakerBundle\CircuitBrokenService
interface.
The class mustn't be marked as final
, because a proxy class is derived from it under the hood.
To configure circuit breaking, you can use the class level configuration or method level configuration.
The class level configuration is valid for all the circuit-broken methods.
It is configured as a class level annotation @CircuitBreakerService
. To mark a public method as circuit broken,
the @CircuitBreaker
annotation or attribute has to be used:
or
The configuration options for the @CircuitBreakerService
are:
- defaultFallback: a public method of the same class which should be called on an exception occurrence, if no fallback is configured for a circuit-broken method.
- ignoreExceptions: exception list, which doesn't trigger marking the wrapped service as failing
The method level annotation @CircuitBreaker
can override the class level configuration
with its own configuration options, which are:
- fallbackMethod: a public method of the same class which should be called on an exception occurrence
- ignoreExceptions: exception list, which doesn't trigger marking the wrapped service as failing
or
The fallback methods have to be public as well.
IMPORTANT: Fallback methods have to have the same method signature as the fallbackable methods, because fallback methods are being called with the same arguments.
IMPORTANT: Doctrine annotations support will be dropped in the future, so it is recommended to use the bundle attributes instead.
NOTICE REGARDING COMPLEX SCENARIOS: It is also possible to define fallback methods for fallback methods in some more complex scenarios. An example of such scenario might be, when there is an API call in the default/fallbackable method. It's fallback method might have a different call to a different API, which means, that such method could use a fallback as well. In that case it can have configured a fallback method which tries to load data from some cache. Such a method might also use a fallback method which might return some default value.
Full example
Enjoy ;)
All versions of circuit-breaker-bundle with dependencies
ackintosh/ganesha Version ^2.0 || ^3.0
beberlei/assert Version ^3.3
doctrine/annotations Version ^1.12|^2.0
symfony/cache Version ^5.4.24|^6.2
symfony/framework-bundle Version ^5.4.24|^6.2
symfony/proxy-manager-bridge Version ^5.4.21|^6.2