zhongjq/thrift-laravel

在Laravel中使用Thrift

0.3.0 2018-08-04 07:05 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:39:16 UTC


README

在Laravel中使用Thrift

如何使用

服务器端

  1. composer require angejia/thrift-laravel

  2. app.providers中添加provider

    \Angejia\Thrift\ThriftServiceProvider::class
    
  3. 在文件config/thrift.php中设置thrift.providers

    // first is service name, defined in thrift file
    // second in Service implement reference, e.g.
    // class ImageServcie implement \Angejia\ImageServiceIf
    ['Angejia.ImageService', \Angejia\ImageService::class],
    
  4. 将Middleware \Angejia\Thrift\Middleware\ThriftServerMiddleware::class 添加到 app\Http\Kernel

    默认情况下,对/rpc的请求将由Middleware处理,如果您想更改此行为,请扩展ThriftServerMiddleware并重写process方法

客户端

  1. composer require angejia/thrift-laravel
  2. app.providers中添加provider
    \Angejia\Thrift\ThriftServiceProvider::class
    
  3. 在文件config/thrift.php中设置thrift.depends
    // key is url
    // value is array of service name
    "https:///rpc" => [
        'Angejia.ImageService',
    ]
    
  4. 用法
    /** @var \Angejia\Thrift\Contracts\ThriftClient $thriftClient */
    $thriftClient = app(\Angejia\Thrift\Contracts\ThriftClient::class);
    /** @var \Angejia\ImageServiceIf $imageService */
    $imageService = $thriftClient->with('Angejia.ImageService');
    
    $result = $imageService->foo();
    

待办事项

  • 单元测试