A tiny rpc framework basing on Netty.
- Customized rpc protocol named
TrpcPrptocol
- Basing on reactor threads model, achieving high performance and high throughput
- Supporting sync and async remoting procedure call
- Supporting multi proxy methods including
Java Proxy
andcglib
- Supporting multi serialization methods including
Java serialization
Fastjson
andHessian
- Achieving service registry and discovery module
- Adding load balance strategy
- Supporting Java SPI, dynamic loading needed modules
- Supporting
router strategy
andcluster fault tolerance
- Exporting services
public interface Interfaces {
String getName(String name);
}
public class InterfacesImpl implements Interfaces {
@Override
public String getName(String name) {
return name + " Shuai";
}
}
public class ServerBootstrap {
@Test
public void doBind() throws InterruptedException {
NettyServer nettyServer = new NettyServer();
nettyServer.doBind(8080);
Thread.sleep(Integer.MAX_VALUE);
}
}
- Remote invoking
public class JdkDynamicProxyTest {
@Test
public void testSync() {
Interfaces interfaces = JdkDynamicProxy.newInstance(Interfaces.class);
System.out.println(interfaces.getName("Junlan"));
}
@Test
public void testAsync() throws InterruptedException {
Interfaces interfaces = JdkDynamicProxy.newInstance(Interfaces.class);
System.out.println(interfaces.getName("hello trpc"));
Thread.sleep(1000);
//do others...
Thread.sleep(1000);
try {
System.out.println(TrpcContext.getContext().getTrpcFuture().get());
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
}
A self-defined protocol which just support trpc framework, detailed designing as follows:
- Magic number(two bytes): identifies trpc protocol with value:
0x0012
- Request type(one byte): three request type, synchronization/asynchronization/one way
- Serialization type(one byte): using which serialization method
- Requested ID(eight bytes): request message id
- Data length(four bytes): the length of the data
- Data: the binary data
Licensed under Apache-2.0
. See LICENSE for further details.