Installation reference:
Zookeeper Installation on Windows (Detailed Step-by-Step Guide, Ensures Success) - CSDN Blog
-
For the first four versions:
- Run
TestServerunder the Server package. - Then run
TestClientunder the Client package.
- Run
-
For later versions:
- Run
ProviderTestfirst. - Then run
ConsumerTest.
- Run
Mac/Linux environments and common issues are detailed in the documentation on the Knowledge Planet platform.
java -versionEnsure the output shows JDK 17 or higher. If not:
- Set
JAVA_HOMEto the JDK 17 installation directory (e.g.,D:\software\JDK17). - Add the JDK
binpath to your system'sPATHvariable.
mvn -vEnsure Maven version is 3.6 or above.
- Download and extract ZooKeeper.
- Rename
zoo_sample.cfgtozoo.cfg. - Start ZooKeeper:
bin\zkServer.cmdNavigate to the project directory:
cd D:\java_stduy\version5
mvn clean install -DskipTestsEnsure the following JARs are generated:
krpc-api/target/krpc-api-1.0-SNAPSHOT.jarkrpc-common/target/krpc-common-1.0-SNAPSHOT.jarkrpc-core/target/krpc-core-1.0-SNAPSHOT.jarkrpc-provider/target/krpc-provider-1.0-SNAPSHOT.jarkrpc-consumer/target/krpc-consumer-1.0-SNAPSHOT.jar
cd D:\java_stduy\version5\krpc-provider
D:\software\JDK17\bin\java -cp "target\krpc-provider-1.0-SNAPSHOT.jar;target\lib\*" com.kama.provider.ProviderTestcd D:\java_stduy\version5\krpc-consumer
D:\software\JDK17\bin\java -cp "target\krpc-consumer-1.0-SNAPSHOT.jar;target\lib\*" com.kama.consumer.ConsumerTest- RPC (Remote Procedure Call Protocol) is a protocol for requesting services from remote systems over the network.
- It abstracts the underlying network details.
- It allows invoking methods on remote systems as if they were local.
- Application-Level Frameworks: Alibaba Dubbo/Dubbox, Google gRPC, Spring Boot/Spring Cloud
- Communication Protocols: RMI, Socket, SOAP (HTTP + XML), REST (HTTP + JSON)
- Communication Libraries: MINA, Netty
- Service Modularization: Facilitates cross-platform communication in microservices.
- Distributed System Architecture: Enables services on different machines to interact.
- Service Reusability: Shared capabilities can be reused by multiple systems.
- System Integration: When app A on server A needs to call methods from app B on server B, RPC handles the cross-memory-space invocation.
- Large-scale websites: With many subsystems and interfaces.
- Service Discovery: Registries like Nacos, Dubbo allow multiple instances of a service to be invoked without awareness of which instance is selected.
- Security: Limits resource exposure.
- Governance: Supports microservices and distributed management.
RPC implementations involve Service Addressing, Serialization/Deserialization, and Network Transmission.
Call ID Mapping:
- Local: Direct function pointers are used.
- Remote: RPC assigns each method a unique Call ID across processes. Clients attach this ID to remote calls. Servers map the Call ID to actual methods using a hash table.
- Serialization: Convert objects into binary for transmission.
- Deserialization: Convert binary back to objects.
Why?
- Since client and server are in separate memory spaces, they cannot share stack/heap directly. Data must be converted to a transferable format (e.g., byte stream) before sending.
Benefits:
- Binary data is easier to transmit.
- Enables cross-platform, cross-language interoperability (e.g., Python client, Java server).
Responsibilities:
- Client sends Call ID and serialized parameters.
- Server sends back the serialized result.
Protocols: TCP, UDP, HTTP
Using TCP:
- Establish socket connection.
- Client sends interface name, method name, serialized params.
- Server deserializes and uses reflection to execute the method.
Using HTTP:
- Client sends REST requests.
- Server returns results in JSON or XML.
Comparison:
- TCP: Lower overhead, higher throughput, better for performance-intensive services. Harder to implement.
- HTTP: Higher-level protocol, easier to use, but introduces more overhead.
- Basic RPC invocation
- Client-side dynamic proxy
- Unified Request and Response definitions
- Introduce Netty for transmission
- Custom message formats
- Use ZooKeeper as service registry
- Netty-based encoder, decoder, and serializer
- Local service cache on client side
- Dynamic service cache update
- Client-side load balancing
- Client fault tolerance with retry on failure
- Service whitelisting
- Service rate limiting and degradation
- Circuit breaker implementation
- SPI mechanism
- Centralized configuration
- Support for multiple serialization formats (Kryo, Hessian, Protostuff)
- Improved shutdown handling
- Distributed log tracing
- Heartbeat detection
- Retry mechanism based on method whitelisting
- Data compression, encryption, and authentication for transmission
- Service registration and consumption via annotations
- Automatically offline nodes with too many failures
- Proactively check offline node status and recover them
- Implement adaptive load balancing






