基于 Netty 实现的 RPC 框架 ZRPC

码农软件 · 软件分类 · 高性能网络开发库 · 2019-08-31 20:59:02

软件介绍

ZRPC

基于Netty实现的RPC框架

服务端

  RpcServer server = new RpcServer("127.0.0.1",1234);
  HelloServiceImpl impl = new HelloServiceImpl();
  server.export(HelloService.class, impl);

客户端

  RpcClient client = new RpcClient("127.0.0.1",1234);
  HelloService service = client.refer(HelloService.class);
  //同步调用
  System.out.println(service.hello("test rpc"));

异步调用

默认的远程调用都是同步的,发起异步调用需要设置RpcContext.setAsync(true),异步调用有两种方式:Future方式、callback方式,可以单独使用也可以混合使用

  • Future方式

  RpcClient client = new RpcClient("127.0.0.1",1234);
  HelloService service = client.refer(HelloService.class);
  RpcContext ctx = RpcContext.getContext();
  ctx.setAsync(true);
  String obj=service.hello("test rpc");
  System.out.println(obj==null);
  Future<String> f =ctx.getFuture();
  System.out.println(f.get());
  • callback方式

  RpcClient client = new RpcClient("127.0.0.1",1234);
  HelloService service = client.refer(HelloService.class);
  RpcContext ctx = RpcContext.getContext();
  ctx.setAsync(true);
  ctx.setCallback(new Callback() {

        @Override
        public void onSuccess(Object result) {
            System.out.println("success  "+ result);
        }
        @Override
        public void onError(Throwable thr) {
               System.out.println("error");
               thr.printStackTrace();
        }
        });
  String obj=service.hello("test rpc");
  System.out.println(obj==null);

单向调用

单向调用是一种特殊类型的异步调用,意味着客户端对本次调用不期待服务端的响应结果。实际上服务端对于单向调用请求也不会作出响应。对于特定场景单向调用性能更好,但并不那么可靠。

//单向调用
  RpcContext ctx = RpcContext.getContext();
  ctx.setOneway(true);
  System.out.println(service.hello("test rpc")==null);

本文地址:https://codercto.com/soft/d/13600.html

雷军传

雷军传

陈润 / 华中科技大学出版社 / 2013-10-1 / 35

讲述雷军20年中从打工者到职业经理人,再到投资家、创业家的职场历程。 这种经历国内绝无仅有,国内有媒体将其比作乔布斯,事实上他比“乔帮主”更精彩,乔是被董事会赶出苹果,而雷从未失败过。 本书以雷军的职场经历和金山、小米的发展历程和雷军投资故事为主线,以时间为脉络,将其20 年商海沉浮的经历完美展现。 通过故事总结和阐释,讲透用人、管理、营销、战略、投资等全方位的经管知识,从雷军身......一起来看看 《雷军传》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试