webfan3/php-easy-breaker
Composer 安装命令:
composer require webfan3/php-easy-breaker
包简介
A php Circuit Breaker
README 文档
README
Circuit breaker is heavily used in microservice architecture to find issues between microservices calls.
The main idea is to protect your code from making unnecessary call if the microservice you call is down.
Features
- Automatic update. (i.e you don't have to manually add success or failure method like other library)
- Return result from the protected function
- Retry timeout
- Exclude some exceptions from being throwned, return null instead.
- Multiprocess updates handled with a cache library. Supports all cache provider from (doctrine cache library).
- Event powered
Full Example:
<?php use Doctrine\Common\Cache\FilesystemCache; use Eljam\CircuitBreaker\Breaker; use Eljam\CircuitBreaker\Event\CircuitEvents; use Symfony\Component\EventDispatcher\Event; require_once __DIR__.'/vendor/autoload.php'; $fileCache = new FilesystemCache('./store', 'txt'); //Create a circuit for github api with a file cache and we want to exclude all exception. $breaker = new Breaker('github_api', ['ignore_exceptions' => true], $fileCache); $breaker->addListener(CircuitEvents::SUCCESS, function (Event $event) { $circuit = $event->getCircuit(); echo "Success:".$circuit->getFailures()."\n"; }); $breaker->addListener(CircuitEvents::FAILURE, function (Event $event) { $circuit = $event->getCircuit(); echo "Increment failure:".$circuit->getFailures()."\n"; }); $breaker->addListener(CircuitEvents::OPEN, function (Event $event) { $circuit = $event->getCircuit(); echo sprintf("circuit %s is open \n", $circuit->getName()); }); $breaker->addListener(CircuitEvents::CLOSED, function (Event $event) { $circuit = $event->getCircuit(); echo sprintf("circuit %s is closed \n", $circuit->getName()); }); $breaker->addListener(CircuitEvents::HALF_OPEN, function (Event $event) { $circuit = $event->getCircuit(); echo sprintf("circuit %s is half-open \n", $circuit->getName()); }); $result = $breaker->protect(function () { throw new \Exception("An error as occured"); // return 'ok'; });
webfan3/php-easy-breaker 适用场景与选型建议
webfan3/php-easy-breaker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 webfan3/php-easy-breaker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webfan3/php-easy-breaker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 75
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-23