andrew-svirin / lumen-microservices
This package is abandoned and no longer maintained.
The author suggests using the andrew-svirin/lumen-microservices package instead.
Microservices Synchronous Requests in Lumen Laravel.
This package has no released version yet, and little information is available.
README
Microservices Synchronous Requests in Laravel Lumen
Supported in Laravel 6.0+ and Laravel Lumen 6.0+
For configuration copy config/microsystem.php
to project dir and setup micro-services inside file.
Installation for Lumen 6.0+
Register service provider in bootstrap/app.php
$app->register(\AndrewSvirin\Microsystem\MicrosystemServiceProvider::class);
Register settings file config/microsystem.php
in bootstrap/app.php
$app->configure('microsystem');
Optional to use facades in bootstrap/app.php
$app->withFacades(true, [ AndrewSvirin\Microsystem\Facades\Microsystem::class => 'Microsystem', ]);
Usage
For example, we need to interact with 2 remote micro-services where we need to get access-token for user.
This example is in test file MicrosystemTest.php
.
$accessToken = AndrewSvirin\Microsystem\Facades\Microsystem:: call(\AndrewSvirin\Microsystem\Data\Requests\Demo1\Request1::create([ 'password' => 'password', ])) // Get password hash. ->next(\AndrewSvirin\Microsystem\Data\Requests\Demo2\Request1::create([ 'password_hash' => function (\AndrewSvirin\Microsystem\Services\ChainResponseCollection $responses) { return $responses->get(0)->getData()['password_hash']; }, 'email' => 'email', ])) // Get user login data using previous responses. ->next(\AndrewSvirin\Microsystem\Data\Requests\Demo1\Request2::create([ 'id' => function (\AndrewSvirin\Microsystem\Services\ChainResponseCollection $responses) { return $responses->get(1)->getData()['id']; }, 'name' => function (\AndrewSvirin\Microsystem\Services\ChainResponseCollection $responses) { return $responses->get(1)->getData()['name']; }, ])) // Get user access token using previous responses. ->getData();
Possible to use Procedure for encapsulate chains logic see example AndrewSvirin\Microsystem\Tests\Data\Procedures\Procedure1.
Services configuration
return [ /* |-------------------------------------------------------------------------- | Microservices definitions. |-------------------------------------------------------------------------- */ 'services' => [ /* |-------------------------------------------------------------------------- | Define Demo 1 microservice configuration. |-------------------------------------------------------------------------- */ 'demo-1' => [ 'format' => 'json', 'server' => [ 'scheme' => 'http', 'host' => 'demo-1.loc', 'port' => 80, 'vhost' => '/api/', ], 'client' => [ 'http_errors' => false, 'decode_content' => false, 'verify' => false, 'cookies' => false, ], ], /* |-------------------------------------------------------------------------- | Define Demo 2 microservice configuration. |-------------------------------------------------------------------------- */ 'demo-2' => [ 'format' => 'json', 'server' => [ 'scheme' => 'http', 'host' => 'demo-2.loc', 'port' => 8080, 'vhost' => '/api/', ], 'client' => [ 'http_errors' => false, 'decode_content' => false, 'verify' => false, 'cookies' => false, ], ], ], ];