Skip to content
Design and Implementation of a Custom RPC Framework

Design and Implementation of a Custom RPC Framework

This article presents a detailed overview of a custom Java RPC framework, covering its core concepts, architecture, communication flow, message protocol, load balancing, serialization, handling of TCP packet fragmentation, and practical implementation using Spring Boot, Netty, and Zookeeper, along with deployment instructions.

IT Architects Alliance
IT Architects Alliance
IT Architects Alliance

RPC (Remote Procedure Call) enables developers to invoke remote services as if they were local methods, abstracting network communication complexities.

The framework consists of three core components: client, server, and a registry (Zookeeper). During a call, the server registers its services, the client discovers them, encodes the request via a proxy, sends it over Netty, the server decodes, invokes the local service, encodes the response, and returns it to the client.

Key roles include service governance, load balancing, fault tolerance, serialization/deserialization, codec, thread pool, dynamic proxy, and optional features such as connection pool, logging, and security.

Load balancing strategies are implemented in rpc-core , supporting round‑robin (FullRoundBalance) and random (RandomBalance) with random as default, configurable via rpc.client.balance.

The custom message protocol follows a "length + content" format to solve TCP packet fragmentation and aggregation, containing fields such as magic number, version, serialization algorithm, message type, status, message ID, data length, and payload.

Serialization is handled in rpc-core using Hessian by default, with optional JSON support.

TCP packet framing issues are addressed by prefixing each message with its length, allowing the decoder to determine when a complete packet has been received.

Implementation uses Spring Boot auto‑configuration: the client starter registers

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.rrtv.rpc.client.config.RpcClientAutoConfiguration

, while the server starter registers analogous configuration. Services are annotated with @RpcService (provider) and injected with @RpcAutowired (consumer). Dynamic proxies and Netty handlers manage request/response processing.

Environment setup requires Windows, IntelliJ IDEA, Spring Boot 2.5.2, JDK 1.8, Netty 4.1.42.Final, Maven, and Zookeeper 3.7.0. After starting Zookeeper, run the provider and consumer applications and test via http://localhost:9090/hello/world?name=hello, which returns “您好:hello”.

The full source code is available at https://gitee.com/listen_w/rpc .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaRPCZooKeeperNettySpring Boot
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.