README 中文版本
基于netty NIO、IO多路复用。
client与server端建立心跳包保活机制。发生未知断连时,重连保证可靠长连接。
使用kryo序列化,自定义传输包,及传输格式,避免TCP沾包问题。
支持zookeeper或nacos做服务注册中心。
可在注解中配置server端业务线程池核心线程数及最大线程数,客户端可通过注解自由选择接口对应负载均衡策略。
可轻松整合SpringBoot进行使用。
com.application.test.api.server.ServerTest.java 服务端启动
com.application.test.api.client.ClientTest.java 客户端启动 并rpc调用HelloService.hello()
与SpringBoot整合启动(由于未发布到远程仓库,所以需本地maven install。)
客户端
<dependency >
<groupId >com.polyu</groupId >
<artifactId >netty-client</artifactId >
<version >1.0-SNAPSHOT</version >
</dependency >
@ Component
public class Test {
@ BRpcConsumer (version = "1.0" , loadBalanceStrategy = RpcLoadBalanceConsistentHash .class , timeOutLength = 1000L )
private static HelloService helloService ;
public static void test () throws InterruptedException {
String yyb = helloService .hello ("yyb" );
System .out .println ("yyb = " + yyb );
}
}
bRPC.client.registry.type =zookeeper
bRPC.client.registry.address =127.0.0.1:2181
bRPC.client.registry.target.name =springbootApplication
bRPC.client.timeout.checkInterval =500
服务端
<dependency >
<groupId >com.polyu</groupId >
<artifactId >netty-server</artifactId >
<version >1.0-SNAPSHOT</version >
</dependency >
@ BRpcProvider (value = HelloService .class , version = "1.0" )
public class HelloServiceImpl implements HelloService {
@ Override
public String hello (String name ) throws InterruptedException {
return name ;
}
}
bRPC.server.application.name =springbootApplication
bRPC.server.address =127.0.0.1:12277
bRPC.server.registry.type =zookeeper
bRPC.server.registry.address =127.0.0.1:2181
Docker Zookeeper部署(例 同样支持nacos)
拉取zk镜像 指令:docker pull zookeeper:3.4.14
查看镜像id 指令:docker images
拉起容器 指令:docker run -d -p 2181:2181 --name b-zookeeper --restart always {imageId}
查看容器id 指令:docker ps -a
进入容器 指令:docker exec -it {containerId} /bin/bash
起注册中心 指令:./bin/zkCli.sh
A netty-based RPC framewor
Based on netty NIO, IO multiplexing.
The client and server establish a heartbeat packet keep-alive mechanism. When an unknown disconnection occurs, reconnection ensures a reliable long connection.
Use kryo serialization, customize the transmission package, and transmission format to avoid TCP packet contamination problems.
Support zookeeper or nacos as service registration center.
The number of core threads and the maximum number of threads in the server-side business thread pool can be configured in the annotations, and the client can freely choose the load balancing strategy corresponding to the interface through the annotations.
Can easily integrate SpringBoot for use.
com.application.test.api.server.ServerTest.java Server start
com.application.test.api.client.ClientTest.java Client starts and rpc calls HelloService.hello()
Start integrated with SpringBoot (Because it is not published to a remote warehouse, it needs local maven install.)
client
<dependency >
<groupId >com.polyu</groupId >
<artifactId >netty-client</artifactId >
<version >1.0-SNAPSHOT</version >
</dependency >
@ Component
public class Test {
@ BRpcConsumer (version = "1.0" , loadBalanceStrategy = RpcLoadBalanceConsistentHash .class , timeOutLength = 1000L )
private static HelloService helloService ;
public static void test () throws InterruptedException {
String yyb = helloService .hello ("yyb" );
System .out .println ("yyb = " + yyb );
}
}
bRPC.client.registry.type =zookeeper
bRPC.client.registry.address =127.0.0.1:2181
bRPC.client.registry.target.name =springbootApplication
bRPC.client.timeout.checkInterval =500
server
<dependency >
<groupId >com.polyu</groupId >
<artifactId >netty-server</artifactId >
<version >1.0-SNAPSHOT</version >
</dependency >
@ BRpcProvider (value = HelloService .class , version = "1.0" )
public class HelloServiceImpl implements HelloService {
@ Override
public String hello (String name ) throws InterruptedException {
return name ;
}
}
bRPC.server.application.name =springbootApplication
bRPC.server.address =127.0.0.1:12277
bRPC.server.registry.type =zookeeper
bRPC.server.registry.address =127.0.0.1:2181
Docker Zookeeper deployment (example also supports nacos)
docker pull zookeeper:3.4.14
docker images
docker run -d -p 2181:2181 --name b-zookeeper --restart always {imageId}
docker ps -a
docker exec -it {containerId} /bin/bash
./bin/zkCli.sh