indigerd/http-fault-tolerance
Composer 安装命令:
composer require indigerd/http-fault-tolerance
包简介
Handle http requests with custom fallback strategies
README 文档
README
Usage
Example of simple usage (by default when http request will fail library will make 1 more attempt to make http request)
use Indigerd\Tolerance\Client; use GuzzleHttp\Client as HttpClient; use Indigerd\Tolerance\Fallback\FallbackFactory; use Indigerd\Tolerance\ResponseFactory; $client = new Client(new HttpClient(), new FallbackFactory(), new ResponseFactory()); $response = $client->request('GET', 'http://facebook.com'); echo($response->getBody());
Example of using with Complex fallback strategy. Complex fallback strategy is a collection of fallbacks that will be called untill one will succeed.
use Indigerd\Tolerance\Client; use GuzzleHttp\Client as HttpClient; use Indigerd\Tolerance\Fallback\FallbackFactory; use Indigerd\Tolerance\ResponseFactory; $client = new Client(new HttpClient(), new FallbackFactory(), new ResponseFactory()); $strategy = new \Indigerd\Tolerance\Fallback\Strategy\Complex( ['retry', new \Indigerd\Tolerance\Fallback\Strategy\Fixture('GGGGGG')], new FallbackFactory() ); $response = $client->request('GET', 'http://google344534534534534534111111.com', [], $strategy); echo($response->getBody());
Example of using library client instead of Guzzle by creating Guzzle decarator. As decorator extends Guzzle Http client you can just inject it in your code with dependency injection without changing your business logic.
use Indigerd\Tolerance\Decorator\GuzzleHttp\Client; $client = new Client();
统计信息
- 总下载量: 613
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-27