轻量级高性能 RPC 框架 HRPC

码农软件 · 软件分类 · RPC/XMLRPC项目 · 2019-04-11 11:13:07

软件介绍

HRPC

 HRPC是一款基于NettyZookeeper设计的轻量级高性能RPC框架。

特性

  • 采用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 ?

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

数字民主的迷思

数字民主的迷思

[美] 马修·辛德曼 / 唐杰 / 中国政法大学出版社 / 2015-12-25 / CNY 39.00

马修·辛德曼著的《数字民主的迷思》主要讨论互联网对美国政治的影响,聚焦的是“民主化”这一课题。针对公众关于网络民主的美好想象与过分狂热,它通过对在线竞选、链接结构、流量模式、搜索引擎使用、博客与博主、内容生产的“规模经济”等主题的深入处理,借助大量数据图表与分析,勾勒出互联网政治的种种局限性。尤其表明,网络政治信息仍然为一小群精英与机构所创造和过滤,在网络的每一个层次和领域都仍然遵循着“赢家通吃”......一起来看看 《数字民主的迷思》 这本书的介绍吧!

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

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具