基于 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

追踪Linux TCP/IP代码运行

追踪Linux TCP/IP代码运行

秦健 / 北京航空航天大学出版社 / 2010-4-1 / 69.00元

本书以应用程序为线索,详细描述了数据包在协议栈的分段、重组、发送、接收过程,同时分析了路由的初始化和设置过程,主要包括socket应用程序、 TCP/IP协议、路由、通知链、邻居子系统等内容。全书涵盖了协议栈的全部知识点,对于广大的读者来说这是一本极其难得的技术资料。同时,书中论述了网络设备的工作原理,解释了RTL8169和嵌入式CS8900、DM9000网卡设备的核心过程。一起来看看 《追踪Linux TCP/IP代码运行》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码