yupmin/laravel-phystrix

一个易于使用的Phystrix集成方案,适用于Laravel应用程序

v1.0.0 2023-01-09 08:14 UTC

This package is auto-updated.

Last update: 2024-09-09 11:54:52 UTC


README

Latest Stable Version Total Downloads License Coding Standards

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)。请参阅许可证文件以获取更多信息。