Flying Pigeon RPC is a very lightweight, easy-to-modify remote call framework that is integrated into real projects, developed based on the NIO framework Netty, easily supports high concurrency, supports service load balancing, seamlessly integrates springFirst, provider configuration
Server configuration feige.properties placed under Classpath
#服务绑定的ip, the number of thread pool threads that are processed by the optional feige.host=127.0.0.1# service Port feige.port=10221# service call feige.poolsize=50feige.host=127.0.0.1# Protocol and object serialization configuration, this configuration is optional, not configured then object serialization using Java native serialization Feige.protocol=io.feige.rpc.protocol.kryo.kryoobjectprotocol
Service export, available in two ways, choose one of the following1. API Export Service
Rpcproducerservice rpcproducerservice = new Rpcproducerservice (); The object is globally unique and cannot be instantiated rpcproducerservice.start (); Rpcproducerservice.exportservice (Serviceinterfacename, SERVICEOBJ );
2. 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: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 "/> <!--export service--><feige:service interface=" Io.feige.rpc.test.provider.TestService "ref=" Testservice "/> </beans>
Second, consumer use configuration
Configuration feige.properties placed under Classpath
#协议以及对象序列化配置, this configuration is optional, does not configure the object serialization using Java native serialization, and if an app includes both the service provider and the caller, the Feige.properties configuration file can be merged feige.protocol= Io.feige.rpc.protocol.kryo.KryoObjectProtocol
The service configuration that needs to be invoked, each service can configure multiple service providers, that is, the configuration of the host, which can be automatically load balanced according to your configuration
Feige-import.xml the file is placed in 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>
Service invocation1. API callsRpcconsumerservice rpcconsumerservice=new Rpcconsumerservice ();//The object is globally unique, do not instantiate Rpcconsumerservice.start (" Feige/feige-import.xml "); Since the connection with the server needs a certain amount of time, there is no success in the call will be abnormal, so this sleep 2 seconds, easy to test Thread.Sleep (2000); Testservice Service=rpcconsumerservice.getproxyservice (Testservice.class); Service.test ();
2. Spring Integration<?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 "> <!--Import Service--<feige:reference interface=" Io.feige.rpc.test.provider.TestService "id=" Testservice "/></beans>
Third, follow-upMonitoring, Autodiscover service, performance optimization, multi-language
Iv. Special Instructions1. When FEIGE.PROTOCOL is configured as Io.feige.rpc.protocol.kryo.KryoObjectProtocol, all classes must have a default constructor, or an error occurs because Kryo relies on the default construction method, but Kryo serialization efficiency is indeed higher than the Java native serialization
2. Service provider and caller Feige.protocol if you want to configure, the configuration must be consistent
Five, downloadJar Package Download: http://www.feige.io/rpc/
Example Project: http://www.feige.io/rpc/samples/
Source Address: http://git.oschina.net/fengfei/feige-rpc/
Introduction to the use of the Fly Pigeon RPC Framework (Java Remote Service invocation)