yupmin/laravel-phystrix

An easy to use Phystrix integration for Laravel applications

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

This package is auto-updated.

Last update: 2024-12-09 12:23:05 UTC


README

Latest Stable Version Total Downloads License Coding Standards

Laravel Phystrix Package using by Modern Phystrix

Requirements

  • PHP 7.1 above
    • ext-json
    • ext-apcu
  • Laravel 5.5 above

Installation

composer require yupmin/laravel-phystrix

Install config

php artisan vendor/publish --provider=Yupmin\Phystrix\ServiceProvider

How to use

Make Phystrix Command

php artisan make:phystrix-command TestCommand

Edit file '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();
    }
}

Run TestCommand

phystrinx(App\Phystrix\TestCommand::class)->execute();
// => "run test"
phystrinx(App\Phystrix\TestCommand::class, false)->execute();
// => "fallback"

Run Phystrix Stream for dashboard (apcu is required.)

Route::get('/phystrix.stream', function () {
    phystrix_stream()->run();
});

License

The MIT License (MIT). Please see License File for more information.