Created
December 9, 2020 05:29
-
-
Save mickaelandrieu/eddb508c545664ea5ef91f1ff8021ba2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Resiliency\MainCircuitBreaker; | |
use Resiliency\Systems\MainSystem; | |
use Resiliency\Storages\SimpleArray; | |
use Resiliency\Clients\SymfonyClient; | |
use Symfony\Component\HttpClient\HttpClient; | |
$client = new SymfonyClient(HttpClient::create()); | |
$mainSystem = MainSystem::createFromArray([ | |
'failures' => 2, | |
'timeout' => 100, | |
'stripped_timeout' => 200, | |
'threshold' => 10000, | |
], $client); | |
$storage = new SimpleArray(); | |
// Any PSR-14 Event Dispatcher implementation. | |
$dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher; | |
$circuitBreaker = new MainCircuitBreaker( | |
$mainSystem, | |
$storage, | |
$dispatcher | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @var Service $service | |
*/ | |
$fallbackResponse = function ($service) { | |
return '{}'; | |
}; | |
$circuitBreaker->call( | |
'https://some-api.domain.com', | |
$fallbackResponse, | |
[ | |
'query' => [ | |
'_token' => '123456789', | |
] | |
] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment