| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

一个几乎零依赖的RPC:eyer-rpc

一个几乎零依赖的RPC,通信网络抛弃了笨重了netty使用了原生的javaNIO包四个类完成封装。
</div>

一个简单的服务 (单机版)

public class TestServer {          public static void main(String[] args) throws IOException {                NioConfig.registered(new KryoSerializer());              final ServerHandler handler = new ServerHandler();              NioConfig.registered(handler);              NioConfig.initSessionHandler();              //需要导出的服务接口 以及对应的实现类              handler.services.put(UserService.class, new RemoteUserService());              Server server = new Server(new InetSocketAddress("0.0.0.0",6161),new Acceptor("acceptor-1",new ReactorPool(1)));            }      }

服务引用

public class ProxyClientTest {          public static void main(String[] args) throws Exception {                    NioConfig.registered(new KryoSerializer());                    final Handler invocationHandler = new ClientHandler();                    NioConfig.registered(invocationHandler);                    NioConfig.registered(new Connector("connector",new ReactorPool(1)));                    NioConfig.initSessionHandler();                      URL url = new URL();                    url.setHost("localhost");                    url.setPort(6161);                    Invoker invoker = new SimpleInvoker(url,50);                      ProxyClient proxyClient = new ProxyClient(invoker);                    final AtomicLong counter = new AtomicLong(0);                    UserService userService = proxyClient.refService(UserService.class);                    userService.save(new User());              clientProxy.close();          }      }

一个简单的服务 (zookeeper注册中心集群版)

集群版本采用和dubbo一样的基于注册中心无状态的模式。可以说是精简版的dubbo
public class ZookeeperServer {            public static void main(String[] args) throws IOException {                NioConfig.registered(new KryoSerializer());              final ServerHandler handler = new ServerHandler();              NioConfig.registered(handler);              NioConfig.initSessionHandler();                handler.services.put(UserService.class, new RemoteUserService());              Server server = new Server(new InetSocketAddress("0.0.0.0", 6161), new Acceptor("acceptor-1", new ReactorPool(1)));                ZooKeeperClient zooKeeperClient = new DefaultZookeeperClient("192.168.1.66:2181");              String format = "/eyer/" + URLEncoder.encode(String.format("rpc/%s:%s/Services", "localhost", 6161), "UTF-8");              zooKeeperClient.create(format, true);          }      }

服务引用

public class ZookeeperClient {          public static void main(String[] args) throws Exception {                    NioConfig.registered(new KryoSerializer());                     final Handler invocationHandler = new ClientHandler();                     NioConfig.registered(invocationHandler);                     NioConfig.registered(new Connector("ZookeeperProxyServicePerf-connector-1",new ReactorPool(1)));                     NioConfig.initSessionHandler();                         Invoker invoker = new ZookeeperInvoker("192.168.1.66:2181",new PollingBalance(),50);                       ProxyClient proxyClient = new ProxyClient(invoker);                         UserService userService = proxyClient.refService(UserService.class);              System.out.println(save);              clientProxy.close();          }      }

项目主页:http://www.open-open.com/lib/view/home/1447491651507

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1447491651507.html
eyer-rpc WEB服务/RPC/SOA