`

简单轻量级的RPC框架—HRPC

阅读更多

HRPC

HRPC is a light-weight high performance RPC framework base on Netty and Zookeeper.

github地址:https://github.com/wosyingjun/HRPC

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 ?

2
0
分享到:
评论
1 楼 manzhizhen 2017-01-12  
建议包名能改成hrpc,而不是yingjun....

相关推荐

    轻量级高性能 RPC 框架 HRPC.zip

    HRPC HRPC是一款基于Netty和Zookeeper设计的轻量级高性能RPC框架。特性采用Protostuff序列化;高性能,负载均衡;支持服务的注册和订阅;支持同步及异步2种调用方式;长连接,自动重连;采用cglib动态代理;代码...

    带有Protobuf服务的简单RPC-Node.js开发

    带有Protobuf Services hrpc的简单RPC带有Protobuf Services npm install hrpc的简单RPC用法首先定义一个RPC服务消息Echo {必需的字符串值= 1; }服务示例{rpc Echo(Echo)返回(Echo){}}然后使用hrpc编译器npm ...

    hrpc-rs:Rust中的hRPC实施

    hrpc-rs 此回购包含Rust中hRPC的实现: hrpc包含通用代码, hrpc-build是可用于protobuf文件的代码生成器, interop是一个示例,用于根据Go示例服务器测试实现和代码生成。

    hrpc-blog:前端开发学习过程

    hrpc-blog blog全在issues里

    drafts:IRTF-HRPC研究小组的草案

    为HRPC构建草稿 安装依赖项: # apt install ruby-kramdown-rfc2629 xml2rfc 草稿编辑工作流程: # $EDITOR draft-glossary.md # make

    High-Performance Computing Using FPGAs

    tightly coupled HRPC architectures, e.g. the Convey hybrid-core computer; reconfigurably networked HPRC architectures, e.g. the QPACE system, and standalone HPRC architectures such as EPFL’s ...

    gohbase:Pure-Go HBase客户端

    )插入一个单元格// Values maps a ColumnFamily -&gt; Qualifiers -&gt; Values.values := map [ string ] map [ string ][] byte { "cf" : map [ string ][] byte { "a" : [] byte { 0 }}}putRequest , err := hrpc ....

Global site tag (gtag.js) - Google Analytics