GithubHelp home page GithubHelp logo

hrpc's Introduction

##HRPC

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

##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

    <!--扫描需求发布的服务所在的包-->
    <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

    <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 ?

hrpc's People

Contributors

wosyingjun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.