介绍 swoft 中 RPC使用:搭建访问服务端和客户端

   

RPC服务端:

一、配置,在文件 /app/bean.php中添加

return [
    'rpcServer'  => [
        'class' => ServiceServer::class,
        'port' => 18308,
    ],
]

Http server 启动中集成 RPC 服务:
return [
    'httpServer' => [
        'class'    => HttpServer::class,
        'port'     => 18306,
        'listener' => [
            'rpc' => bean('rpcServer')
        ],

        // ...
    ],
]

 

二、使用

Swoft2.x 小白学习笔记 (四) --- RPC

 

 

   1、定义接口,服务提供方定义好接口格式,存放到公共的lib库里面,服务调用方,加载lib库,就能使用接口服务,接口定义和普通接口完全一致。

 在/app/Rpc/Lib/ 文件夹下添加文件DemoInterface.php:

<?php

namespace App\Rpc\Lib;

/**
 * Interface DemoInterface
 */
interface DemoInterface{
    /**
     * @return array
     * @param int $id
     */
    public function getLists(int $id): array ;

    /**
     * @return string
     */
    public function getBig():string ;
}
View Code

相关文章:

  • 2022-02-27
  • 2021-11-11
  • 2022-01-18
  • 2021-05-30
  • 2022-01-04
  • 2021-04-07
  • 2021-12-30
  • 2021-09-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-06-11
  • 2021-08-04
  • 2022-01-10
相关资源
相似解决方案