OldSmokeGun / lumen-yar by OldSmokeGun

use yar extension in lumen
114
0
2
Package Data
Maintainer Username: OldSmokeGun
Maintainer Contact: 504645946@qq.com (oldSmokeGun)
Package Create Date: 2020-04-06
Package Last Update: 2020-04-06
Language: PHP
License: Apache-2.0
Last Refreshed: 2024-11-23 03:22:08
Package Statistics
Total Downloads: 114
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

yar 扩展在 lumen 框架中的简单封装

客户端

配置

  • config/service.php
<?php

return [
    'goods_service' => [
        'remote' => env('GOODS_SERVICE_REMOTE')
    ],
    'shop_service' => [
        'remote' => env('SHOP_SERVICE_REMOTE')
    ]
    // ...
];
  • bootstrap/app.php
$app->configure('service');

调用

try 
{

    $result = (new oldSmokeGun\Rpc\Client\Client(config('service.goods_service.remote'), 'Demo'))
        ->call('Foo', ['name' => 'bob']);

    dd($result);

} catch (Yar_Client_Exception $exception) {
    // TODO
}

服务器端

注意: 路由 /rpc/{service} 已被注册

配置

  • bootstrap/app.php
$app->register(oldSmokeGun\Rpc\Providers\RpcServiceProvider::class);

使用

  • App/Services 目录下新建 Demo.php
<?php

namespace App\Services;

class Demo
{
    public function foo()
    {
        return 'this is demo';
    }

}