定制 esd-cloud/saber-cloud-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

esd-cloud/saber-cloud-plugin

Composer 安装命令:

composer require esd-cloud/saber-cloud-plugin

包简介

saber-cloud-plugin

README 文档

README

使用saber进行微服务访问,声明试web服务客户端

通过接口描述web客户端行为,服务提供方和调用方共用接口,服务提供方实现接口。

接口描述

/**
 * @RequestMapping("test")
 * Interface IRestController
 */
interface IRestController
{
    /**
     * get请求
     * @GetMapping("/")
     * @return string
     */
    public function hello();

    /**
     * get请求
     * @GetMapping("test/{name}")
     * @PathVariable("name")
     * @RequestParam("id")
     * @param $name
     * @param $id
     * @return string
     */
    public function test($name, $id);

}

服务提供方AnnRestController

/**
 * @RestController()
 * Class TestController
 * @package ESD\Plugins\EasyRoute
 */
class AnnRestController extends EasyController implements IRestController
{

    /**
     * 找不到方法时调用
     * @param $methodName
     * @return mixed
     */
    protected function defaultMethod(?string $methodName)
    {
        // TODO: Implement defaultMethod() method.
    }

    /**
     * get请求
     * @GetMapping("/")
     * @return string
     */
    public function hello()
    {
        return "hello";
    }

    /**
     * get请求
     * @GetMapping("test/{name}")
     * @PathVariable("name")
     * @RequestParam("id")
     * @param $name
     * @param $id
     * @return string
     */
    public function test($name, $id)
    {
        return "hello"
    }
}

客户端RestClient

/**
 * @SaberClient(host="http://127.0.0.1:8082",fallback=RestClientFallback::class)
 * Interface RestClient
 * @package ESD\Plugins\SaberCloud\ExampleClass\Clients
 */
interface RestClient extends IRestController
{

}

客户端降级结果RestClientFallback

class RestClientFallback implements RestClient
{

    /**
     * get请求
     * @GetMapping("/")
     * @return string
     */
    public function hello()
    {
        return "hello";
    }

    /**
     * get请求
     * @GetMapping("test/{name}")
     * @PathVariable("name")
     * @RequestParam("id")
     * @param $name
     * @param $id
     * @return string
     */
    public function test($name, $id)
    {
        return "test";
    }
}

使用客户端

    /**
     * @Inject()
     * @var RestClient
     */
    private $restClient;
    
     /**
     * get请求
     * @GetMapping("/")
     * @return string
     */
    public function hello()
    {
        return $this->restClient->hello();
    }

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固