1 Star 1 Fork 51

mslsoftware / feige-rpc

forked from 小飞 / feige-rpc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

####飞鸽RPC是一个非常轻量级,且容易修改整合到实际项目中的远程调用框架,基于NIO框架netty开发,轻松支持高并发,支持服务负载均衡,无缝整合spring

##一、provider配置

服务器配置 feige.properties 放在classpath下

#服务绑定的ip,可选
feige.host=127.0.0.1
#服务端口
feige.port=10221
#服务调用时处理线程池线程数量
feige.poolsize=50
feige.host=127.0.0.1
#协议以及对象序列化配置,本配置为可选,不配置则对象序列化使用java原生序列化
feige.protocol=io.feige.rpc.protocol.kryo.KryoObjectProtocol

###服务导出,提供两种方式,任选一种即可

####1. API导出服务

RpcProducerService rpcProducerService = new RpcProducerService(); //该对象全局唯一即可,不能重复实例化
rpcProducerService.start();
rpcProducerService.exportService(serviceInterfaceName, serviceObj);

####2. 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:feige="http://www.feige.io/feige" xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd http://www.feige.io/feige http://www.feige.io/feige/feige.xsd">
    <bean id="testService" class="io.feige.rpc.test.provider.impl.TestServiceImpl"/> 
    <!-- 导出服务 --></br>
    <feige:service interface="io.feige.rpc.test.provider.TestService" ref="testService" /> 
</beans>

##二、consumer使用配置

配置 feige.properties 放在classpath下

#协议以及对象序列化配置,本配置为可选,不配置则对象序列化使用java原生序列化;如果一个应用同时包括服务提供者和调用者 feige.properties配置文件可以合并
feige.protocol=io.feige.rpc.protocol.kryo.KryoObjectProtocol

需要调用的服务配置,每个服务可以配置多个服务提供者,即host的配置,可以根据你的配置自动进行负载均衡

feige-import.xml 该文件放在classpath:feige/feige-import.xml
<?xml version="1.0" encoding="UTF-8"?>	
<remote-services>
        <remote-service> 
	        <interface>io.feige.rpc.TestService</interface> 
			<invoke-timeout>30</invoke-timeout> 
			<hosts> 
				<host> 
					<ip>130.255.2.107</ip> 
					<port>10221</port> 
					<!--权重,数字越大权重越高--> 
					<weight>1</weight> 
				</host> 
				<host> 
					<ip>130.255.2.107</ip> 
					<port>10222</port> 
				    <weight>2</weight> 
		        </host> 
	        </hosts>
    </remote-service>
</remote-services>

###服务调用 ####1. API调用

RpcConsumerService rpcConsumerService=new RpcConsumerService();//该对象全局唯一即可,不要重复实例化 
rpcConsumerService.start("feige/feige-import.xml"); 
//由于与服务器建连需要一定时间,还没有建连成功就调用会出异常,所以这睡眠2秒,便于测试 
Thread.sleep(2000); 
TestService service=rpcConsumerService.getProxyService(TestService.class); 
service.test();

####2. 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:feige="http://www.feige.io/feige" xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd http://www.feige.io/feige http://www.feige.io/feige/feige.xsd">
	<!-- 导入服务 -->
	<feige:reference interface="io.feige.rpc.test.provider.TestService" id="testService" /> 
</beans>

##三、后续 监控、自动发现服务、性能优化、多语言

##四、特别说明 1.feige.protocol配置为io.feige.rpc.protocol.kryo.KryoObjectProtocol时,所有类必需有默认构造方法,否则会出错,因为kryo依赖默认构造方法,但kryo序列化效率确实比java原生序列化高 2.服务提供者与调用者feige.protocol如果要配置,配置必需一致 ##五、下载 jar包下载:http://www.feige.io/rpc/
示例项目:http://www.feige.io/rpc/samples/

The MIT License (MIT) Copyright (c) 2014 小飞 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

飞鸽RPC是一个非常轻量级,且容易修改整合到实际项目中的JAVA远程调用框架,基于NIO框架netty开发,轻松支持高并发,支持服务负载均衡,无缝整合spring 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/jsmth/feige-rpc.git
git@gitee.com:jsmth/feige-rpc.git
jsmth
feige-rpc
feige-rpc
master

搜索帮助