百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

NettyRpc

> 后端框架
开源

基于 Netty、ZooKeeper 和 Spring 的简单 RPC 框架

2.4K stars0 点赞3 次浏览
访问官网GitHub

工具介绍

基于 Netty、ZooKeeper 和 Spring 的简单 RPC 框架

NettyRpc

基于 Netty、ZooKeeper 和 Spring 的 RPC 框架 中文详情:Chinese Details ##### 特性: * 代码和框架简单 * ZooKeeper 支持服务注册/发现 * 高可用性、负载均衡和故障转移 * 支持不同的负载均衡策略 * 支持异步/同步调用 * 支持不同版本的服务 * 支持不同的序列化器/反序列化器 * 使用心跳检测死机的 TCP 连接 ##### 设计: ##### 如何使用 (netty-rpc-test) 1. 定义接口: public interface HelloService { String hello(String name); String hello(Person person); } 2. 使用 @NettyRpcService 注解实现接口: ```
@NettyRpcService(HelloService.class, version = "1.0") public class HelloServiceImpl implements HelloService { public HelloServiceImpl(){}

    @Override
    public String hello(String name) {
        return "Hello " + name;
    }

    @Override
    public String hello(Person person) {
        return "Hello " + person.getFirstName() + " " + person.getLastName();
    }
}
``` 3. 运行 ZooKeeper
  1. 启动服务器:
    1. 使用 Spring 配置启动服务器: RpcServerBootstrap
    2. 无需使用 Spring 配置启动服务器: RpcServerBootstrap2
  2. 调用服务:
    1. 使用客户端:
   	final RpcClient rpcClient = new RpcClient("127.0.0.1:2181");
   		
   	// Sync call
   	HelloService helloService = rpcClient.createService(HelloService.class, "1.0");
   	String result = helloService.hello("World");
   		
   	// Async call
   	RpcService client = rpcClient.createAsyncService(HelloService.class, "2.0");
   	RPCFuture helloFuture = client.call("hello", "World");
   	String result = (String) helloFuture.get(3000, TimeUnit.MILLISECONDS);
	```
 
    2. 使用注解 @RpcAutowired:

public class Baz implements Foo { @RpcAutowired(version = "1.0") private HelloService helloService1;

@RpcAutowired(version = "2.0")
private HelloService helloService2;

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javanettyrpc-frameworkspringzookeeper

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架