Hyperf jsonrpc

依赖的 composer 包

composer require hyperf/json-rpc

composer require hyperf/rpc-server

composer require hyperf/rpc-client

composer require hyperf/service-governance

composer require hyperf/service-governance-consul

composer require hyperf/service-governance-nacos

`

复制代码
<?php

namespace App\JsonRpc;

use Hyperf\RpcServer\Annotation\RpcService;

/**
 * 注意,如希望通过服务中心来管理服务,需在注解内增加 publishTo属性 值为consul, protocol是协议,默认是jsonrpc-http, 这里演示TCP协议 故使用 jsonrpc
 * @RpcService(name="FooService ", protocol="jsonrpc", server="jsonrpc-tcp", publishTo="consul")
 */
class FooService implements FooServiceInterface
{
    /**
     * @inheritDoc
     */
    public function hello()
    {
        return 'This is Foo JsonRpc Service.';
    }
}

配置hyperf服务启动 `/conifg/autoload/server.php` 这里演示TCP协议

复制代码
。。。

[

    'name' => 'jsonrpc-tcp',

    'type' => \Hyperf\Server\Server::SERVER_BASE,

    'host' => '0.0.0.0',

    'port' => 9503,

    'sock_type' => SWOOLE_SOCK_TCP,

    'callbacks' => [

        \Hyperf\Server\Event::ON_RECEIVE => [\Hyperf\JsonRpc\TcpServer::class, 'onReceive'],

    ],

    'settings' => [

        'open_eof_split' => true,

        'package_eof' => "\r\n",

        'package_max_length' => 1024 * 1024 * 2,

    ],

],

配置注册中心 /conifg/autoload/services.php

复制代码
return [
    'enable'    => [
        // 开启服务发现
        'discovery' => true,
        // 开启服务注册
        'register'  => true,
    ],
    // 服务消费者相关配置
    'consumers' => [],
    // 服务提供者相关配置
    'providers' => [],
    // 服务驱动相关配置
    'drivers'   => [
        'consul' => [
            
        ],
        'nacos' => [
        
        ],
    ],
];
相关推荐
FfHUCisI8 小时前
GMP 调度器:Go 并发的心脏是如何跳动的
开发语言·golang·php
星云API技术支持9 小时前
企业微信二次开发外部群:群聊数据与联系人信息如何建立关联
数据库·php·企业微信
sbjdhjd1 天前
PHP eval 型 RCE:flag 正则过滤与通配符绕过实操 | 01
安全·web安全·网络安全·开源·系统安全·php·网络攻击模型
qetfw1 天前
Debian Nginx + PHP-FPM 配置:FastCGI、站点目录与访问验证
linux·nginx·debian·php
啊阿狸不会拉杆2 天前
《计算机网络-自顶向下方法》3.6 拥塞控制原理 读书笔记
计算机网络·智能路由器·php
郑州光合科技余经理2 天前
本地生活服务系统:成品模块和定制接口怎么划界
java·前端·人工智能·后端·系统架构·php·ai编程
LorryJovens2 天前
【LAAP科研】CEN因果等价网络理论---从双缝干涉到因果等价
开发语言·php
Casual2 天前
【网络基础进阶】:看懂子网划分与 VLAN
开发语言·网络·php
0xBADCODE2 天前
CTF Writeup 合集
安全·web安全·网络安全·系统安全·密码学·php·ctf
IPdodo_2 天前
静态 IP 访问异常排查:403/429 归因与迁移验收
服务器·网络·数据库·python·网络协议·php·性能测试