1. Go to this page and download the library: Download ssvwsm/grpc-base-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ssvwsm / grpc-base-laravel example snippets
namespace App\Services\MicroserviceGrpc;
use SSVWSM\GrpcLaravel\Client\Contracts\BaseGrpcApi;
use Google\Protobuf\Internal\Message;
use Illuminate\Http\Request;
use Protobuf\Company\ExampleServiceClient;
/**
* @method Message ExampleMethod(array|Request $request)
*/
class ExampleGrpcClient extends BaseGrpcApi
{
public function grpcClient(): string
{
return ExampleServiceClient::class;
}
}
...
// ExampleMethod is a method of ExampleServiceClient;
(new ExampleGrpcClient())->ExampleMethod($request);
...
$clientGrpc = (new GrpcFactory)->make(ExampleServiceClient::class);
...
use SSVWSM\GrpcLaravel\Client\Traits\HandleDataRequest;
...
class ExampleController extends Controller
{
use HandleDataRequest;
}
declare(strict_types=1);
use App\Grpc\ExampleGrpcController;
use Spiral\Goridge\StreamRelay;
use Spiral\RoadRunner\Worker;
ini_set('display_errors', 'stderr');
;
$app->singleton(
SSVWSM\GrpcLaravel\Server\Contracts\ServiceInvoker::class,
SSVWSM\GrpcLaravel\Server\LaravelServiceInvoker::class
);
$kernel = $app->make(SSVWSM\GrpcLaravel\Server\Kernel::class);
$kernel->registerService(ExampleGrpcController::class);
$w = new Worker(new StreamRelay(STDIN, STDOUT));
$kernel->serve($w);