per3evere / preq
Microservices IPC command factory for Laravel && Lumen
Installs: 2 878
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- guzzlehttp/promises: ^1.4.0
- illuminate/support: ^5.8|^6.0|^7.0|^8.0
Requires (Dev)
- phpunit/phpunit: ^7.0|^8.0|^9.0
Suggests
- laravel/framework: To test the Laravel bindings
- laravel/lumen-framework: To test the lumen bindings
README
About Preq
Preq is a latency and fault tolerance library for Laravel && Lumen, inspired by Netflix’s Hystrix and upwork/phystrix
Installation
Require this package with composer:
composer require per3evere/preq --dev
Add ServiceProvider
Laravel
add this to the providers array in config/app.php
Per3evere\Preq\PreqServiceProvider::class
Lumen
add this in bootstrap/app.php
$app->register(Per3evere\Preq\PreqServiceProvider::class);
Usage
Create service command file
namespace App\Services; use Per3evere\Preq\AbstractCommand; class Example extends AbstractCommand { /** * 同步执行命令. * * @return void */ public function run() { return 'run!'; } /** * 异步执行命令. * * @return \Guzzlehttp\Promise\Promise; */ public function runAsync() { // 返回注意返回类型. } }
execute it
$command = app('preq')->getCommand(\App\Services\Example::class); // 同步执行命令 echo $command->execute(); // 异步执行命令 $command->queue();