Download the PHP package tourze/symfony-circuit-breaker-bundle without Composer
On this page you can find all versions of the php package tourze/symfony-circuit-breaker-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/symfony-circuit-breaker-bundle
More information about tourze/symfony-circuit-breaker-bundle
Files in tourze/symfony-circuit-breaker-bundle
Package symfony-circuit-breaker-bundle
Short Description 为 Symfony 应用提供分布式熔断器功能,支持故障隔离和服务降级
License MIT
Informations about the package symfony-circuit-breaker-bundle
Symfony Circuit Breaker Bundle
中文
Symfony熔断器Bundle,为Symfony应用提供高性能、可扩展的熔断器功能, 支持单机和集群环境,帮助您构建更健壮的微服务应用。
Table of Contents
- 功能特性
- 安装
- 快速开始
- 使用注解(Attribute)方式
- 直接使用服务
- 使用带熔断功能的HTTP客户端
- Configuration
- Environment Variable Configuration
- Configuration Parameters
- Dependencies
- Required Dependencies
- Optional Dependencies
- Storage Backends
- 命令行工具
- 高级用法
- 手动管理熔断状态
- 自定义HTTP客户端降级处理
- 贡献指南
- 参考资料
- 许可证
功能特性
- 高性能存储:使用Redis原子操作,支持滑动窗口统计
- 多层故障转移:Redis → Doctrine → Memory,确保熔断器始终可用
- 多种熔断策略:失败率策略、慢调用策略、连续失败策略
- 集群支持:基于共享存储的状态同步,支持分布式部署
- 监控接口:提供JSON格式的REST API查看熔断器状态
- 灵活配置:纯环境变量配置,支持全局和特定熔断器配置
- 命令行工具:查看状态、重置、强制开关等操作
安装
通过Composer安装:
在Symfony项目中注册Bundle:
快速开始
使用注解(Attribute)方式
在控制器方法上使用熔断器注解:
直接使用服务
通过依赖注入使用熔断器服务:
使用带熔断功能的HTTP客户端
如果需要手动获取带熔断功能的HTTP客户端:
Configuration
Environment Variable Configuration
Circuit breaker supports configuration through environment variables, which can be set in the .env file:
Configuration Parameters
FAILURE_RATE_THRESHOLD: Failure rate threshold (percentage)MINIMUM_NUMBER_OF_CALLS: Minimum number of callsPERMITTED_NUMBER_OF_CALLS_IN_HALF_OPEN_STATE: Allowed calls in half-open stateWAIT_DURATION_IN_OPEN_STATE: Wait duration in open state (seconds)SLIDING_WINDOW_SIZE: Sliding window sizeSLOW_CALL_DURATION_THRESHOLD: Slow call duration threshold (milliseconds)SLOW_CALL_RATE_THRESHOLD: Slow call rate threshold (percentage)CONSECUTIVE_FAILURE_THRESHOLD: Consecutive failure threshold
Dependencies
Required Dependencies
- PHP: 8.1 or higher
- Symfony: 6.4 or higher
- PSR/Log: For logging functionality
Optional Dependencies
- Redis: For high-performance storage (recommended)
- Doctrine DBAL: For database storage fallback
- Symfony/HttpClient: For HTTP client circuit breaker functionality
Storage Backends
Redis Storage (Recommended)
For production environments with high performance requirements:
Doctrine Storage
When Redis is unavailable, automatically fallback to Doctrine storage:
Memory Storage
For development and testing only, does not support multiple instances.
命令行工具
查看熔断器配置信息:
查看特定服务的熔断状态:
重置特定服务的熔断状态:
强制打开熔断器(测试降级功能):
强制关闭熔断器:
高级用法
手动管理熔断状态
你可以通过依赖注入获取熔断器服务,并手动管理熔断状态:
自定义HTTP客户端降级处理
你可以通过自定义的HTTP客户端降级工厂来处理熔断时的HTTP请求:
然后创建你的降级工厂:
贡献指南
我们欢迎任何形式的贡献!请在贡献之前阅读以下指南:
如何贡献
- 报告问题:如果您发现了 bug 或有功能请求,请在 GitHub Issues 中创建一个 issue
- 代码贡献:
- Fork 本仓库
- 创建新的功能分支 (
git checkout -b feature/amazing-feature) - 提交您的更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 创建 Pull Request
代码风格
- 遵循 PSR-12 编码标准
- 使用 PHP 8.1+ 的现代语法特性
- 所有公共方法必须有完整的 PHPDoc 注释
- 变量和方法命名使用有意义的英文描述
测试要求
- 所有新功能必须包含相应的单元测试
- 测试覆盖率应保持在 80% 以上
- 运行测试:
./vendor/bin/phpunit packages/symfony-circuit-breaker-bundle/tests - 代码质量检查:
./vendor/bin/phpstan analyse packages/symfony-circuit-breaker-bundle
Pull Request 指南
- PR 标题应该清晰描述更改内容
- 包含详细的更改说明
- 确保所有测试通过
- 保持 commit 历史的整洁
参考资料
许可证
本包基于 MIT 许可证。详情请参见 LICENSE 文件。
All versions of symfony-circuit-breaker-bundle with dependencies
doctrine/dbal Version ^4.0
psr/log Version ^3|^2|^1
symfony/cache Version ^7.3
symfony/config Version ^7.3
symfony/console Version ^7.3
symfony/dependency-injection Version ^7.3
symfony/event-dispatcher Version ^7.3
symfony/event-dispatcher-contracts Version ^3
symfony/framework-bundle Version ^7.3
symfony/http-client Version ^7.3
symfony/http-client-contracts Version ^3.6
symfony/http-foundation Version ^7.3
symfony/http-kernel Version ^7.3
symfony/property-access Version ^7.3
symfony/routing Version ^7.3
symfony/yaml Version ^7.3
tourze/doctrine-indexed-bundle Version 1.0.*
tourze/enum-extra Version 1.0.*
tourze/redis-dedicated-connection-bundle Version 1.0.*
tourze/symfony-dependency-service-loader Version 1.0.*
tourze/symfony-routing-auto-loader-bundle Version 1.0.*