Skip to content

Instantly share code, notes, and snippets.

@mickaelandrieu
Created December 9, 2020 05:29
Embed
What would you like to do?
<?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