简单轻量级的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

简单轻量级的RPC框架—HRPC_第1张图片

Service Registry

简单轻量级的RPC框架—HRPC_第2张图片

Server Tutorial

1.Spring configuration



    
    
    

    
    
        
        
    

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



    
    
    
    
        
        
        
            
                com.yingjun.rpc.service.OrderService
                com.yingjun.rpc.service.UserService
                com.yingjun.rpc.service.GoodsService
            
        
    


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 ?

你可能感兴趣的:(rpc,分布式,框架)