轻量级高性能 RPC 框架 HRPC
- 授权协议: GPL
- 开发语言: Java
- 操作系统: 跨平台
- 软件首页: https://github.com/wosyingjun/HRPC
- 软件文档: https://github.com/wosyingjun/HRPC
软件介绍
HRPC
特性
采用Protostuff序列化;
高性能,负载均衡;
支持服务的注册和订阅;
支持同步及异步2种调用方式;
长连接,自动重连;
采用cglib动态代理;
代码简答,易上手;
支持Spring;
HRPC结构图
服务注册中心
服务端
1. 通过Spring配置
<?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. 服务接口
public interface UserService {
public User getUser(String phone);
public User updateUser(User user);
}3. 注册服务实现
@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;
}
}客户端
1. Spring配置
<?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. 同步调用
UserService userService = rpcClient.createProxy(UserService.class);
User user1 = userService.getUser("188888888");
logger.info("result:" + user1.toString());3. 异步调用
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");为什么选择Protostuff ?
算法统治世界——智能经济的隐形秩序
徐恪、李沁 / 清华大学出版社有限公司 / 2017-11-15 / CNY 69.00
今天,互联网已经彻底改变了经济系统的运行方式,经济增长的决定性要素已经从物质资料的增加转变成为信息的增长。但是,只有信息的快速增长是不够的,这些增长的信息还必须是“有序”的。只有“有序”才能使信息具有价值,能够为人所用,能够指导我们实现商业的新路径。这种包含在信息里的隐形秩序才是今天信息世界的真正价值所在。经济系统的运行确实是纷繁复杂的,但因为算法的存在,这一切变得有律可循,算法也成为新经济系统里......一起来看看 《算法统治世界——智能经济的隐形秩序》 这本书的介绍吧!
