简单轻量级的RPC框架—HRPC
来源:互联网 发布:仁显王后的男人 知乎 编辑:程序博客网 时间:2024/05/24 06:29
Features
- Serialize by protostuff
- High performance, load balance and failover
- Service registration and subscription base on zookeeper
- Support asynchronous or synchronous invoking
- Keep-Alived connection, reconnect to server automatically
- Dynamic proxy by cglib
- Write less do more
- Spring support
HRPC Structure
Service Registry下载
Server Tutorial
1.Spring configuration下载
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--扫描需求发布的服务所在的包--> <context:component-scan base-package="com.yingjun.rpc.service.impl"/> <context:property-placeholder location="classpath:system.properties"/> <!--服务端配置--> <bean id="rpcServer" class="com.yingjun.rpc.server.RPCServer"> <constructor-arg name="zookeeper" value="${zookeeper.address}"/> <constructor-arg name="serverAddress" value="${server.address}"/> </bean></beans>
2.Service interfacne
public interface UserService { public User getUser(String phone); public User updateUser(User user);}
3.Provide rpc service下载
@HRPCService(UserService.class)public class UserServiceImpl implements UserService { @Override public User getUser(String phone) { User user =new User(111,"yingjun",phone); return user; } @Override public User updateUser(User user) { user.setName("yingjun@update"); return user; }}
Client Tutorial
1. Spring configuration下载
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config/> <context:property-placeholder location="classpath:system.properties"/> <!--客户端配置--> <bean id="rpcClient" class="com.yingjun.rpc.client.RPCClient"> <constructor-arg name="zookeeper" value="${zookeeper.address}"/> <!--订阅需要用到的接口--> <constructor-arg name="interfaces"> <list> <value>com.yingjun.rpc.service.OrderService</value> <value>com.yingjun.rpc.service.UserService</value> <value>com.yingjun.rpc.service.GoodsService</value> </list> </constructor-arg> </bean></beans>
2. Synchronous invoking
UserService userService = rpcClient.createProxy(UserService.class);User user1 = userService.getUser("188888888");logger.info("result:" + user1.toString());
3. Asynchronous invoking下载
AsyncRPCProxy asyncProxy = rpcClient.createAsyncProxy(UserService.class);asyncProxy.call("getUser", new AsyncRPCCallback() { @Override public void success(Object result) { logger.info("result:" + result.toString()); } @Override public void fail(Exception e) { logger.error("result:" + e.getMessage()); } }, "188888888");
Why choose protostuff ?
0 0
- 简单轻量级的RPC框架—HRPC
- php的轻量级rpc框架yar
- 一个轻量级的分布式RPC框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- 轻量级分布式 RPC 框架
- Windows7资源管理器中输入字母定位自动变搜索解决
- Javascript—产生随机数
- 解决Eclipse建立Maven项目后无法建立src/main/java资源文件夹的办法
- 图文介绍XCode常用快捷键大全
- C++ 3种继承的区别
- 简单轻量级的RPC框架—HRPC
- Window下通过命令行查看\结束进程
- 深入浅出 RPC - 浅出篇
- 【用Cocos Creator给暗恋的女生写一个游戏(13)】——整体回顾,工程文件
- 在python IDLE中打开python Shell,就可以直接用import导入当前模块了
- vs2012/2013/...扩展工具
- 《一流员工的十大职业素养》——培训分享
- JavaScript模拟用户单击事件
- VS2010调试后台服务【附加到进程】