A high-performance Java RPC Framework based on Netty.
- Simple coding and easy to use
- Support both synchronous calls and asynchronous calls
- Support idle connections detection with heartbeat and auto closure
- Support RPC-level hooks
- Support transmission of primitive data types as well as custom data types
public interface SimpleService {
String hello(Person person);
}public class SimpleServiceImpl implements SimpleService {
@Override
public String hello(Person person) {
return "hello, name=" + person.getName() + ", age=" + person.getAge();
}
}// register the service on 127.0.0.1:8080
RpcServer rpcServer = new RpcServer("127.0.0.1", 8080).registerService(SimpleServiceImpl.class);
// run the server
rpcServer.run();Synchronous calls
// create a client
RpcClient rpcClient = new RpcClient("127.0.0.1", 8080);
// specify the idle time of a connection
// RpcClient rpcClient = new RpcClient(HOST, PORT, 2000L);
// discover the service
SimpleService simpleService = rpcClient.syncService(SimpleService.class);
// synchronous RPC
String helloMsg = simpleService.hello(new Person());
// synchronous RPC with timeout
String helloMsg = simpleService.hello(new Person());
// shutdown the client
rpcClient.shutDown();Asynchronous calls and synchronous calls
// discover the service
RpcService rpcService = rpcClient.asyncService(SimpleService.class);
// get a future instance as the result of the asynchronous call
RpcFuture rpcFuture = rpcService.asyncCall("hello", new Person());
// get the RPC result synchronously
rpcFuture.get();
// get the RPC result immediately
rpcFuture.getNow();
// add a RPC hook
rpcFuture.addRpcHook(new RpcHook() {
@Override
public void beforeRpc(RpcRequest rpcRequest) {
/* ... */
}
@Override
public void afterRpc(RpcResponse rpcResponse) {
/* ... */
}
});- Enable annotation-driven development
- Enable other serialization/deserialization techniques
- Enable auto-reconnection
- Enable service-registry and service-discovery with Zookeeper
- Enable integration into Spring framework