微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HRPC 轻量级高性能 RPC 框架

程序名称:HRPC

授权协议: GPL

操作系统: 跨平台

开发语言: Java

HRPC 介绍

HRPC

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

特性

HRPC结构图

服务注册中心

服务端

通过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>
public interface UserService {
    public User getUser(String phone);
    public User updateUser(User user);
}
@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;
    }
}

客户端

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>
UserService userService = rpcclient.createProxy(UserService.class);
User user1 = userService.getUser(188888888);
logger.info(result: + user1.toString());
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);

https://github.com/wosyingjun/HRPC#why-choose-protostuff

为什么选择Protostuff ?

HRPC 官网

https://github.com/wosyingjun/HRPC

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐