yupmin/ laravel-phystrix
一个易于使用的Phystrix集成方案,适用于Laravel应用程序
v1.0.0
2023-01-09 08:14 UTC
Requires
- php: ^7.4|^8.0|^8.1|^8.2
- ext-apcu: *
- ext-json: *
- yupmin/modern-phystrix: ^5.0
Requires (Dev)
- nunomaduro/collision: ^4.3|^5.11|^6.3
- orchestra/testbench: ^5.0|^6.0|^7.0
- squizlabs/php_codesniffer: ^3.7
README
Laravel Phystrix 包使用现代Phystrix
要求
- PHP 7.1以上
- ext-json
- ext-apcu
- Laravel 5.5以上
安装
composer require yupmin/laravel-phystrix
安装配置
php artisan vendor/publish --provider=Yupmin\Phystrix\ServiceProvider
如何使用
创建Phystrix命令
php artisan make:phystrix-command TestCommand
编辑文件 'app/Phystrix/TestCommand.php'
class TestCommand extends AbstractCommand { protected $wantFallback; public function __construct($wantFallback = false) { $this->wantFallback = $wantFallback; } /** * @param bool $wantFallback * @return mixed * @throws Exception */ protected function run() { if ($this->wantFallback) { throw new Exception("fallback"); } return 'run test'; } /** * @param Exception|null $exception * @return mixed */ protected function getFallback(?Exception $exception = null) { return $exception->getMessage(); } }
运行TestCommand
phystrinx(App\Phystrix\TestCommand::class)->execute(); // => "run test" phystrinx(App\Phystrix\TestCommand::class, false)->execute(); // => "fallback"
运行Phystrix Stream以显示仪表板(需要apcu
。)
Route::get('/phystrix.stream', function () { phystrix_stream()->run(); });
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。