pixelfederation / phystrix-bundle
Phystrix 与 Symfony2 框架集成。
4.0.1
2021-02-24 14:35 UTC
Requires
- php: >=7.4
- odesk/phystrix: ^2.0
- symfony/config: ^5.0
- symfony/dependency-injection: ^5.0
- symfony/http-kernel: ^5.0
- symfony/yaml: ^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18
- nikic/php-parser: ^4.10
- php-parallel-lint/php-parallel-lint: ^1.2
- phpcompatibility/php-compatibility: ^9.3
- phpmd/phpmd: ^2.9
- phpro/grumphp: ^1.3
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- sensiolabs/security-checker: ^6.0
- slevomat/coding-standard: ^6.0
- squizlabs/php_codesniffer: 3.5.6
- vimeo/psalm: ^4.6
README
Phystrix Bundle
此包提供了带有默认配置的 phystrix 命令工厂服务:phystrix.command_factory
安装
使用 Composer 安装组件。更新您的项目 composer.json
文件以包含依赖项。
"require": { "pixelfederation/phystrix-bundle": "~1.1" }
在您的 AppKernel
中注册包
class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Odesk\Bundle\PhystrixBundle\OdeskPhystrixBundle() // ... ); } }
配置
默认配置
app/config/config.yml
odesk_phystrix: default: fallback: ~ circuitBreaker: errorThresholdPercentage: 50 forceOpen: false forceClosed: false requestVolumeThreshold: 20 sleepWindowInMilliseconds: 5000 metrics: healthSnapshotIntervalInMilliseconds: 1000 rollingStatisticalWindowInMilliseconds: 10000 rollingStatisticalWindowBuckets: 10 requestCache: ~ requestLog: ~
Web Profiler
Phystrix 包附带一个 Web Profiler 插件,当启用 Symfony Profiler 时,它会自动启用。您只需确保请求日志功能已开启。
odesk_phystrix: default: requestLog: enabled: true
仅在启用 Profiler 的模式/环境中执行此操作。
使用方法
您可以使用 phystrix.service_locator
在运行时提供额外的依赖项
$container->get('phystrix.service_locator')->set('somekey', $somevalue);
如何创建和运行一个命令
$command = $container->get('phystrix.command_factory')->getCommand('MyCommand', $parameter1, $parameter2); $command->execute();
日志记录器
如何将日志记录器添加到 Commands:定义 logger.phystrix
服务
# config.yml monolog: channels: ['phystrix']
和
# services.yml services: logger.phystrix: alias: monolog.logger.phystrix
Redis 状态存储
需要 redis 状态存储 pixelfederation/phystrix-redis 包
composer require pixelfederation/phystrix-redis
覆盖状态存储配置
# services.yml services: PixelFederation\Phystrix\Storage\RedisStateStorage: arguments: - '@snc_redis.cache' phystrix.state_storage: alias: PixelFederation\Phystrix\Storage\RedisStateStorage
许可证
此文件是 Phystrix Bundle 的一部分
版权 2013-2017 Upwork Global Inc. 保留所有权利。
此文件根据 Apache License 2.0 许可(“许可证”);除非您遵守许可证,否则不得使用此文件。您可以在以下位置获得许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言、许可和限制,请参阅许可证。