sunlong/thrift-laravel

在 Laravel 中使用 Thrift

0.3.4 2018-11-28 11:23 UTC

This package is auto-updated.

Last update: 2024-09-29 01:24:13 UTC


README

在 Laravel 中使用 Thrift

如何使用

服务器端

  1. composer require sunlong/thrift-laravel

  2. app.providers 中添加提供者

    \sunlong\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 \sunlong\ImageServiceIf
    ['sunlong.ImageService', \sunlong\ImageService::class],
    
  4. 将 Middleware \sunlong\Thrift\Middleware\ThriftServerMiddleware::class 添加到 app\Http\Kernel

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

客户端

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

待办事项

  • 单元测试