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");
相关推荐
HRPC HRPC是一款基于Netty和Zookeeper设计的轻量级高性能RPC框架。特性采用Protostuff序列化;高性能,负载均衡;支持服务的注册和订阅;支持同步及异步2种调用方式;长连接,自动重连;采用cglib动态代理;代码...
嵌入式系统开发_STM32微控制器_ESP8266WiFi模块_心率传感器_加速度计_OLED显示屏_蓝牙40_低功耗设计_实时操作系统_智能手表_多功能健康监测_运动数据记录_
驾校自动化_网页自动化爬虫技术_Python27多线程HTTP请求模拟_龙泉驾校2014版约车系统自动预约助手_通过模拟登录和循环请求实现自动约车功能_支持失败自动递增车号重试_
Linux系统编程_操作系统内核_系统调用_进程线程_信号处理_文件IO_进程间通信_多线程同步_网络编程_UNIX环境编程_中文翻译勘误_错误修正_代码示例优化_技术文档校对_开
wanjunshe_Python-Tensorflow_12888_1745868924470
scratch少儿编程逻辑思维游戏源码-铅笔画.zip
即时通讯应用开发_基于LeanCloud云服务与Android原生开发_集成QQ第三方登录与即时聊天功能的社交应用_实现用户注册登录创建聊天室发送文字消息展示用户信息头像昵称并提供
scratch少儿编程逻辑思维游戏源码-伞兵大乱斗(云变量).zip
scratch少儿编程逻辑思维游戏源码-楼层酷跑.zip
scratch少儿编程逻辑思维游戏源码-零下之寒颤.zip
scratch少儿编程逻辑思维游戏源码-密室逃生.zip
少儿编程scratch项目源代码文件案例素材-爪猫足球.zip
命令行完成git本地仓库创建、将代码提交到暂存区、查看暂存区信息、将代码提交到本地仓库、将本地仓库关联到远程仓库、推送到远程仓库全过程的截图
少儿编程scratch项目源代码文件案例素材-纸.zip
scratch少儿编程逻辑思维游戏源码-日本冒险.zip
scratch少儿编程逻辑思维游戏源码-狼人杀跑酷.zip
scratch少儿编程逻辑思维游戏源码-史莱姆杀手.zip
少儿编程scratch项目源代码文件案例素材-粘粘世界.zip
scratch少儿编程逻辑思维游戏源码-米克 demo.zip
网络游戏开发_Netty4X框架_多协议支持_高性能分布式游戏服务器_基于TCP_UDP_HTTP_WebSocket协议栈_Protobuf自定义通信协议_RPC远程调用_My