Skip to content

Instantly share code, notes, and snippets.

@mickaelandrieu
Created December 9, 2020 05:29
Show Gist options
  • Save mickaelandrieu/eddb508c545664ea5ef91f1ff8021ba2 to your computer and use it in GitHub Desktop.
Save mickaelandrieu/eddb508c545664ea5ef91f1ff8021ba2 to your computer and use it in GitHub Desktop.
<?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
);
<?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