- 授权协议: GPL
- 开发语言: Java
- 操作系统: 跨平台
- 软件首页: http://git.oschina.net/sandyfog/zrpc
- 软件文档: http://git.oschina.net/sandyfog/zrpc
软件介绍
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);
程序员成长的烦恼
吴亮、周金桥、李春雷、周礼 / 华中科技大学出版社 / 2011-4 / 28.00元
还在犹豫该不该转行学编程?还在编程的道路上摸爬滚打?在追寻梦想的道路上你并不孤单,《程序员成长的烦恼》中的四位“草根”程序员也曾有过类似的困惑。看看油田焊接技术员出身的周金桥是如何成功转行当上程序员的,做过钳工、当过外贸跟单员的李春雷是如何自学编程的,打小在486计算机上学习编程的吴亮是如何一路坚持下来的,工作中屡屡受挫、频繁跳槽的周礼是如何找到出路的。 《程序员成长的烦恼》记录了他们一步一......一起来看看 《程序员成长的烦恼》 这本书的介绍吧!
