This repository build a remote procedure call framework, which contains several highlights:
- Use SPI (Service Provider Interface) to enhance the scalability.
- Implement several internet transport methods, including Socket and Netty.
- Implement several serialize methods, including Protostuff and jackson.
- Use Zookeeper as the register center.
- Implementation of the heartbeat mechanism to ensure stable connections.
- Customized message protocol, avoid packet concatenation and half packet happen, see
RpcMessageDecoder/RpcMessageEncoder
. - Implement consistent hashing algorithm for zookeeper load balancing.
- Java 1.8 and Docker
- Pull Zookeeper from docker hub.
docker pull zookeeper:3.5.8
- This repository is developed using Intellij IDEA, not tested with other IDEs.
- This repository is coded with Lombok annotations, users need to install Lombok plugin to successfully compile.
- Add
src/main/resources
into your IDE's classpath.
- Users can edit configs in path
src/main/resources/
or add services insrc/main/resources/META-INF/extensions
. - Start Zookeeper service, default port: 2181.
docker run -d --name zookeeper -p 2181:2181 zookeeper:3.5.8
- Users can run the test codes in path
src/test/java
.
- Compile and run
socketTest.ServerMain
first. - Compile and run
socketTest.ClientMain
afterwords. - If it runs properly you can see the result in the output。
Server-Side (Service Provider)
THE_SERVICE_YOU_WANT_TO_PROVIDE targetRpcService = TargetRpcService.builder()
.group("THE_GROUP_OF_THE_SERVICE_YOU_WANT_TO_PROVIDE")
.version("THE_VERSION_OF_THE_SERVICE_YOU_WANT_TO_PROVIDE")
.service(THE_OBJECT_OF_THE_SERVICE_YOU_WANT_TO_PROVIDE)
.build();
SocketRpcServer socketRpcServer = new SocketRpcServer();
socketRpcServer.registerService(targetRpcService);
socketRpcServer.start();
Client-Side (Service User)
RpcRequestTransport rpcRequestTransport = new SocketRpcClient();
TargetRpcService targetRpcService = TargetRpcService.builder()
.group("THE_GROUP_OF_THE_SERVICE_YOU_WANT_TO_IMPLEMENT")
.version("THE_VERSION_OF_THE_SERVICE_YOU_WANT_TO_IMPLEMENT")
.build();
RpcClientProxy rpcClientProxy = new RpcClientProxy(rpcRequestTransport, targetRpcService);
THE_SERVICE_YOU_WANT_TO_IMPLEMENT service = rpcClientProxy.getProxy(ClassTransferTest.class);
service.doSth();
- guide-rpc-framework: https://github.com/Snailclimb/guide-rpc-framework
- dourpc-remoting: https://xilidou.com/2018/09/26/dourpc-remoting/