yupmin-ct / laravel-phystrix

An easy to use Phystrix integration for Laravel applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 $exception
     * @return mixed
     */
    public function getFallback(Exception $exception)
    {
        return $exception->getMessage();
    }
}

Run TestCommand

phystrinx(App\Phystrix\TestCommand::class)->exercute();
// => "run test"
phystrinx(App\Phystrix\TestCommand::class, false)->exercute();
// => "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

License:MIT License


Languages

Language:PHP 100.0%