Skip to content

An easy to use Phystrix integration for Laravel applications

License

Notifications You must be signed in to change notification settings

yupmin/laravel-phystrix

Repository files navigation

Laravel Phystrix

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.

About

An easy to use Phystrix integration for Laravel applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages