# eyer **Repository Path**: captain/eyer ## Basic Information - **Project Name**: eyer - **Description**: 使用java nio包 书写的RPC - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 15 - **Created**: 2015-08-31 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 一个简单的服务 (单机版) public class TestServer { public static void main(String[] args) throws IOException { NioConfig.registered(new KeyoCodec()); final ServerHandler invocationHandler = new ServerHandler(); NioConfig.registered(invocationHandler); NioConfig.initSessionHandler(); NioConfig.initSessionHandler(); Acceptor acceptor = new Acceptor(new ReactorPool(1)); acceptor.start(); ServerProxy server = new ServerProxy("localhost", 6161, acceptor); //需要导出的服务接口 以及对应的实现类 server.exportService(UserService.class, new RemoteUserService()); server.start(); System.out.println("start server in port ; 6161"); } } ### 服务引用 public class ProxyClientTest { public static void main(String[] args) throws Exception { NioConfig.registered(new KeyoCodec()); final Handler invocationHandler = new ClientHandler(); NioConfig.registered(invocationHandler); NioConfig.registered(new Connector(new ReactorPool(1))); NioConfig.initSessionHandler(); URL url = new URL(); url.setHost("localhost"); url.setPort(6161); Invoker invoker = new DefaultInvoker(url,new PollingBalance(),50); ClientProxy clientProxy = new ClientProxy(invoker); UserService userService = clientProxy.refService(UserService.class); User save = userService.save(new User()); System.out.println(save); clientProxy.close(); } } ### 一个简单的服务 (zookeeper注册中心集群版) ###### 集群版本采用和dubbo一样的基于注册中心无状态的模式。可以说是精简版的dubbo public class ZookeeperServer { public static void main(String[] args) throws IOException { NioConfig.registered(new KeyoCodec()); final ServerHandler invocationHandler = new ServerHandler(); NioConfig.registered(invocationHandler); NioConfig.initSessionHandler(); NioConfig.initSessionHandler(); Acceptor acceptor = new Acceptor(new ReactorPool(1)); acceptor.start(); ZookeeperServerProxy zookeeperServerProxy = new ZookeeperServerProxy("127.0.0.1",6363,acceptor,"192.168.1.66:2181"); zookeeperServerProxy.exportService(UserService.class,new RemoteUserService()); zookeeperServerProxy.start(); } } ### 服务引用 public class ZookeeperClient { public static void main(String[] args) throws Exception { NioConfig.registered(new KeyoCodec()); final Handler invocationHandler = new ClientHandler(); NioConfig.registered(invocationHandler); NioConfig.registered(new Connector(new ReactorPool(1))); NioConfig.initSessionHandler(); String zkUrl = "192.168.1.66:2181"; Invoker invoker = new ZookeeperInvoker(zkUrl,new PollingBalance(),50); ClientProxy clientProxy = new ClientProxy(invoker); UserService userService = clientProxy.refService(UserService.class); User save = userService.save(new User()); System.out.println(save); clientProxy.close(); } }