Laravel Phystrix Package using by Modern Phystrix
- PHP 7.1 above
- ext-json
- ext-apcu
- Laravel 5.5 above
composer require yupmin/laravel-phystrix
Install config
php artisan vendor/publish --provider=Yupmin\Phystrix\ServiceProvider
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();
});
The MIT License (MIT). Please see License File for more information.