安吉家/thrift-laravel

在 Laravel 中使用 Thrift

0.2.13 2016-09-19 07:23 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:43:16 UTC


README

在 Laravel 中使用 Thrift

如何使用

服务器端

  1. composer require angejia/thrift-laravel

  2. app.providers 中添加提供者

    \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. 将中间件 \Angejia\Thrift\Middleware\ThriftServerMiddleware::class 添加到 app\Http\Kernel

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

客户端

  1. composer require angejia/thrift-laravel
  2. app.providers 中添加提供者
    \Angejia\Thrift\ThriftServiceProvider::class
    
  3. 在文件 config/thrift.php 中设置 thrift.depends
    // key is url
    // value is array of service name
    "http://localhost/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();
    

待办事项

  • 单元测试