a lightweight rpc framework demo based on netty, zookeeper, spring
一个基于Netty,Zookeeper,Spring的一个轻量级框架。
- rpc-common:通用工具包
- rpc-registry: 注册中心接口
- rpc-registry-zookeeper: 注册中心Zookeeper实现
- rpc-server: 生产者服务端
- rpc-client: 消费者客户端
-
定义生产者接口(rpc-sample-api)
public interface HelloService { String hello(String name); String hello(Person person); }
-
生产者实现(rpc-sample-server)
// 该注解标志这是一个生产者的接口实现 @RpcService(HelloService.class) public class HelloServiceImpl implements HelloService{ @Override public String hello(String name) { return "hello! " + name; } @Override public String hello(Person person) { return "Hello! " + person.getFirstName() + " " + person.getLastName(); } } // 启动类 public class RpcBootstrap { public static void main(String[] args) { log.debug("start server"); new ClassPathXmlApplicationContext("spring.xml"); } }
-
消费者实现(rpc-sample-client)
public class HelloClient { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); RpcProxy rpcProxy = context.getBean(RpcProxy.class); HelloService helloService = rpcProxy.create(HelloService.class); String result = helloService.hello("world"); System.out.println(result); } }