A lightweight RPC (Remote Procedure Call) framework built with:
- Netty for network communication
- Nacos for service registry and discovery
- Java Dynamic Proxy for client-side invocation
- Maven multi-module architecture
This project demonstrates how to build a minimal but complete RPC framework from scratch.
rpc-master
│
├── rpc-common # Common request/response models & service map
├── rpc-client # Client-side RPC implementation
├── rpc-server # Server-side RPC implementation
├── rpc-registry # Service registry abstraction (Nacos-based)
├── rpc-sample-api # Example service API
├── rpc-sample-server # Example server implementation
└── rpc-sample-client # Example client usage
Client Proxy
│
▼
RpcClient → NettyClient → Network → NettyServer → RequestHandler
│ │
▼ ▼
Service Registry (Nacos) ServiceProvider
- Client invokes an interface method.
- Dynamic proxy builds an
RpcRequest. - Netty client sends the request to the server.
- Server receives the request and delegates it to
RequestHandler. RequestHandlerfinds the implementation viaServiceProvider.- Server executes the method using reflection.
- The result is returned as an
RpcResponse.
Contains shared models:
RpcRequestRpcResponseServiceProvider
Encapsulates:
- Interface name
- Method name
- Parameter types
- Parameters
Encapsulates:
- Result
- Status
- Error message (if any)
Handles client-side RPC invocation.
UserService userService = rpcClientProxy.getProxy(UserService.class);Responsibilities:
- Intercepts method calls
- Creates
RpcRequest - Sends request via Netty
Handles server-side request processing.
Core responsibilities:
- Locate service implementation
- Use reflection to invoke method
- Wrap result into
RpcResponse
Service registration and discovery.
Defines:
register()lookup()
Uses Nacos for service registry and a simple load balancing strategy.
startup.cmd (Windows)
./startup.sh (Linux/Mac)
Default address:
http://localhost:8848
Run:
rpc-sample-server/ServerTest
Run:
rpc-sample-client/ClientTest
- Java 8+
- Netty
- Nacos
- Maven
- Fastjson (for serialization)
This project demonstrates:
- Client-side proxy abstraction
- Netty-based communication
- Registry-driven service discovery
- Reflection-based invocation
- Modular design
It provides a solid foundation for building a production-grade RPC system.