├── dubbo1.jpg ├── dubbo2.jpg ├── sample ├── rpc-sample-app │ ├── src │ │ └── test │ │ │ ├── resources │ │ │ ├── rpc.properties │ │ │ ├── log4j.properties │ │ │ └── spring.xml │ │ │ └── java │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── sample │ │ │ └── app │ │ │ └── HelloServiceTest.java │ ├── target │ │ ├── test-classes │ │ │ ├── rpc.properties │ │ │ ├── com │ │ │ │ └── itjoyee │ │ │ │ │ └── rpc │ │ │ │ │ └── sample │ │ │ │ │ └── app │ │ │ │ │ └── HelloServiceTest.class │ │ │ ├── log4j.properties │ │ │ └── spring.xml │ │ └── classes │ │ │ └── META-INF │ │ │ ├── MANIFEST.MF │ │ │ └── maven │ │ │ └── com.itjoyee.rpc │ │ │ └── rpc-sample-app │ │ │ ├── pom.properties │ │ │ └── pom.xml │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── .project │ ├── .classpath │ └── pom.xml ├── rpc-sample-client │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── target │ │ └── classes │ │ │ ├── META-INF │ │ │ ├── MANIFEST.MF │ │ │ └── maven │ │ │ │ └── com.itjoyee.rpc │ │ │ │ └── rpc-sample-client │ │ │ │ ├── pom.properties │ │ │ │ └── pom.xml │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── sample │ │ │ └── client │ │ │ ├── Person.class │ │ │ └── HelloService.class │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── sample │ │ │ └── client │ │ │ ├── HelloService.java │ │ │ └── Person.java │ ├── .project │ ├── .classpath │ └── pom.xml └── rpc-sample-server │ ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs │ ├── src │ └── main │ │ ├── resources │ │ ├── rpc.properties │ │ ├── log4j.properties │ │ └── spring.xml │ │ └── java │ │ └── com │ │ └── itjoyee │ │ └── rpc │ │ └── sample │ │ └── server │ │ ├── RpcBootstrap.java │ │ └── HelloServiceImpl.java │ ├── target │ └── classes │ │ ├── rpc.properties │ │ ├── META-INF │ │ ├── MANIFEST.MF │ │ └── maven │ │ │ └── com.itjoyee.rpc │ │ │ └── rpc-sample-server │ │ │ ├── pom.properties │ │ │ └── pom.xml │ │ ├── com │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── sample │ │ │ └── server │ │ │ ├── RpcBootstrap.class │ │ │ └── HelloServiceImpl.class │ │ ├── log4j.properties │ │ └── spring.xml │ ├── .project │ ├── .classpath │ └── pom.xml ├── framework ├── rpc-common │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── target │ │ └── classes │ │ │ ├── META-INF │ │ │ ├── MANIFEST.MF │ │ │ └── maven │ │ │ │ └── com.itjoyee.rpc │ │ │ │ └── rpc-common │ │ │ │ ├── pom.properties │ │ │ │ └── pom.xml │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── common │ │ │ ├── RpcDecoder.class │ │ │ ├── RpcEncoder.class │ │ │ ├── RpcRequest.class │ │ │ ├── RpcResponse.class │ │ │ └── SerializationUtil.class │ ├── .project │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── common │ │ │ ├── RpcEncoder.java │ │ │ ├── RpcResponse.java │ │ │ ├── RpcDecoder.java │ │ │ ├── RpcRequest.java │ │ │ └── SerializationUtil.java │ ├── .classpath │ └── pom.xml ├── rpc-base-client │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── target │ │ └── classes │ │ │ ├── META-INF │ │ │ ├── MANIFEST.MF │ │ │ └── maven │ │ │ │ └── com.itjoyee.rpc │ │ │ │ └── rpc-base-client │ │ │ │ ├── pom.properties │ │ │ │ └── pom.xml │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── client │ │ │ ├── RpcClient.class │ │ │ ├── RpcProxy.class │ │ │ ├── RpcClient$1.class │ │ │ └── RpcProxy$1.class │ ├── .project │ ├── .classpath │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── itjoyee │ │ └── rpc │ │ └── client │ │ ├── RpcProxy.java │ │ └── RpcClient.java ├── rpc-base-server │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ ├── target │ │ └── classes │ │ │ ├── META-INF │ │ │ ├── MANIFEST.MF │ │ │ └── maven │ │ │ │ └── com.itjoyee.rpc │ │ │ │ └── rpc-base-server │ │ │ │ ├── pom.properties │ │ │ │ └── pom.xml │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── server │ │ │ ├── RpcServer.class │ │ │ ├── RpcHandler.class │ │ │ ├── RpcServer$1.class │ │ │ └── RpcService.class │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── itjoyee │ │ │ └── rpc │ │ │ └── server │ │ │ ├── RpcService.java │ │ │ ├── RpcHandler.java │ │ │ └── RpcServer.java │ ├── .project │ ├── .classpath │ └── pom.xml └── rpc-zookeeper-registry │ ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs │ ├── target │ └── classes │ │ ├── META-INF │ │ ├── MANIFEST.MF │ │ └── maven │ │ │ └── com.itjoyee.rpc │ │ │ └── rpc-zookeeper-registry │ │ │ ├── pom.properties │ │ │ └── pom.xml │ │ └── com │ │ └── itjoyee │ │ └── rpc │ │ └── registry │ │ ├── Constant.class │ │ ├── ServiceRegistry.class │ │ ├── ServiceDiscovery$1.class │ │ ├── ServiceDiscovery$2.class │ │ ├── ServiceDiscovery.class │ │ └── ServiceRegistry$1.class │ ├── src │ └── main │ │ └── java │ │ └── com │ │ └── itjoyee │ │ └── rpc │ │ └── registry │ │ ├── Constant.java │ │ ├── ServiceRegistry.java │ │ └── ServiceDiscovery.java │ ├── .project │ ├── .classpath │ └── pom.xml └── README.md /dubbo1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/dubbo1.jpg -------------------------------------------------------------------------------- /dubbo2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/dubbo2.jpg -------------------------------------------------------------------------------- /sample/rpc-sample-app/src/test/resources/rpc.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/test-classes/rpc.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 -------------------------------------------------------------------------------- /framework/rpc-common/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /framework/rpc-base-client/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /framework/rpc-base-server/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /framework/rpc-common/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/src/main/resources/rpc.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 3 | 4 | # rpc server 5 | server.address=127.0.0.1:8000 -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/rpc.properties: -------------------------------------------------------------------------------- 1 | # zookeeper server 2 | registry.address=127.0.0.1:2181 3 | 4 | # rpc server 5 | server.address=127.0.0.1:8000 -------------------------------------------------------------------------------- /framework/rpc-base-client/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /framework/rpc-base-server/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Administrator 3 | Build-Jdk: 1.7.0_65 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcDecoder.class -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcEncoder.class -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcRequest.class -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcResponse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-common/target/classes/com/itjoyee/rpc/common/RpcResponse.class -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcClient.class -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcProxy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcProxy.class -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcServer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcServer.class -------------------------------------------------------------------------------- /sample/rpc-sample-app/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | encoding//src/test/resources=UTF-8 5 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcClient$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcClient$1.class -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcProxy$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-client/target/classes/com/itjoyee/rpc/client/RpcProxy$1.class -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcHandler.class -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcServer$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcServer$1.class -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-base-server/target/classes/com/itjoyee/rpc/server/RpcService.class -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/com/itjoyee/rpc/common/SerializationUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-common/target/classes/com/itjoyee/rpc/common/SerializationUtil.class -------------------------------------------------------------------------------- /sample/rpc-sample-client/target/classes/com/itjoyee/rpc/sample/client/Person.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/sample/rpc-sample-client/target/classes/com/itjoyee/rpc/sample/client/Person.class -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/Constant.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/Constant.class -------------------------------------------------------------------------------- /sample/rpc-sample-client/target/classes/com/itjoyee/rpc/sample/client/HelloService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/sample/rpc-sample-client/target/classes/com/itjoyee/rpc/sample/client/HelloService.class -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/com/itjoyee/rpc/sample/server/RpcBootstrap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/sample/rpc-sample-server/target/classes/com/itjoyee/rpc/sample/server/RpcBootstrap.class -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/test-classes/com/itjoyee/rpc/sample/app/HelloServiceTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/sample/rpc-sample-app/target/test-classes/com/itjoyee/rpc/sample/app/HelloServiceTest.class -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/com/itjoyee/rpc/sample/server/HelloServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/sample/rpc-sample-server/target/classes/com/itjoyee/rpc/sample/server/HelloServiceImpl.class -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceRegistry.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceRegistry.class -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceDiscovery$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceDiscovery$1.class -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceDiscovery$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceDiscovery$2.class -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceDiscovery.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceDiscovery.class -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceRegistry$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jiajianfa/rpc/HEAD/framework/rpc-zookeeper-registry/target/classes/com/itjoyee/rpc/registry/ServiceRegistry$1.class -------------------------------------------------------------------------------- /sample/rpc-sample-client/src/main/java/com/itjoyee/rpc/sample/client/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.sample.client; 2 | 3 | public interface HelloService { 4 | 5 | String hello(String name); 6 | 7 | String hello(Person person); 8 | } 9 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 3 | org.eclipse.jdt.core.compiler.compliance=1.7 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.7 6 | -------------------------------------------------------------------------------- /framework/rpc-base-client/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 3 | org.eclipse.jdt.core.compiler.compliance=1.7 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.7 6 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 3 | org.eclipse.jdt.core.compiler.compliance=1.7 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.7 6 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 3 | org.eclipse.jdt.core.compiler.compliance=1.7 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.7 6 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.target=System.out 5 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.console.layout.ConversionPattern=%m%n 7 | 8 | log4j.logger.com.itjoyee.rpc=DEBUG -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.target=System.out 5 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.console.layout.ConversionPattern=%m%n 7 | 8 | log4j.logger.com.itjoyee.rpc=DEBUG -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/test-classes/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.target=System.out 5 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.console.layout.ConversionPattern=%m%n 7 | 8 | log4j.logger.com.itjoyee.rpc=DEBUG -------------------------------------------------------------------------------- /sample/rpc-sample-server/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG,console 2 | 3 | log4j.appender.console=org.apache.log4j.ConsoleAppender 4 | log4j.appender.console.target=System.out 5 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 6 | log4j.appender.console.layout.ConversionPattern=%m%n 7 | 8 | log4j.logger.com.itjoyee.rpc=DEBUG -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-common/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:29:02 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-common 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\framework\\rpc-common 7 | artifactId=rpc-common 8 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-sample-app/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:29:43 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-sample-app 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\sample\\rpc-sample-app 7 | artifactId=rpc-sample-app 8 | -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-base-client/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:30:11 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-base-client 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\framework\\rpc-base-client 7 | artifactId=rpc-base-client 8 | -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-base-server/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:29:58 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-base-server 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\framework\\rpc-base-server 7 | artifactId=rpc-base-server 8 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-sample-client/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:29:02 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-sample-client 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\sample\\rpc-sample-client 7 | artifactId=rpc-sample-client 8 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-sample-server/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:29:29 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-sample-server 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\sample\\rpc-sample-server 7 | artifactId=rpc-sample-server 8 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-zookeeper-registry/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Wed Jan 21 16:29:17 CST 2015 3 | version=1.0.0-SNAPSHOT 4 | groupId=com.itjoyee.rpc 5 | m2e.projectName=rpc-zookeeper-registry 6 | m2e.projectLocation=C\:\\Users\\Administrator\\Desktop\\rpc\\framework\\rpc-zookeeper-registry 7 | artifactId=rpc-zookeeper-registry 8 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/src/main/java/com/itjoyee/rpc/sample/server/RpcBootstrap.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.sample.server; 2 | 3 | import org.springframework.context.support.ClassPathXmlApplicationContext; 4 | 5 | /** 6 | * @author itjoyee 7 | * 服务容器启动类 8 | */ 9 | public class RpcBootstrap { 10 | 11 | public static void main(String[] args) { 12 | new ClassPathXmlApplicationContext("spring.xml"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/src/main/java/com/itjoyee/rpc/registry/Constant.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.registry; 2 | 3 | /** 4 | * 常量 5 | * @author itjoyee 6 | * @since 1.0.0 7 | */ 8 | public interface Constant { 9 | 10 | /** 11 | * zookeeper客户端session超时时间 12 | */ 13 | int ZK_SESSION_TIMEOUT = 5000; 14 | 15 | /** 16 | *zookeeper的znode根路径 17 | */ 18 | String ZK_REGISTRY_PATH = "/registry"; 19 | 20 | /** 21 | * zookeeper上注册的服务的根路径 22 | */ 23 | String ZK_DATA_PATH = ZK_REGISTRY_PATH + "/services"; 24 | } -------------------------------------------------------------------------------- /framework/rpc-base-server/src/main/java/com/itjoyee/rpc/server/RpcService.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.server; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * RPC 请求注解(标注在服务实现类上) 11 | * 12 | * @author itjoyee 13 | * @since 1.0.0 14 | */ 15 | @Target({ElementType.TYPE}) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Component 18 | public @interface RpcService { 19 | 20 | Class value(); 21 | } 22 | -------------------------------------------------------------------------------- /framework/rpc-common/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-common 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-sample-app 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /framework/rpc-base-client/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-base-client 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /framework/rpc-base-server/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-base-server 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-sample-client 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-sample-server 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rpc-zookeeper-registry 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/src/main/java/com/itjoyee/rpc/sample/server/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.sample.server; 2 | 3 | import com.itjoyee.rpc.sample.client.HelloService; 4 | import com.itjoyee.rpc.sample.client.Person; 5 | import com.itjoyee.rpc.server.RpcService; 6 | 7 | /** 8 | * @author itjoyee 9 | * rpc服务 10 | */ 11 | @RpcService(HelloService.class) 12 | public class HelloServiceImpl implements HelloService { 13 | 14 | public String hello(String name) { 15 | return "Hello! " + name; 16 | } 17 | 18 | public String hello(Person person) { 19 | return "Hello! " + person.getFirstName() + " " + person.getLastName(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /framework/rpc-common/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.7 13 | -------------------------------------------------------------------------------- /framework/rpc-base-server/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.7 13 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.7 13 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/src/main/java/com/itjoyee/rpc/sample/client/Person.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.sample.client; 2 | 3 | public class Person { 4 | 5 | private String firstName; 6 | private String lastName; 7 | 8 | public Person() { 9 | } 10 | 11 | public Person(String firstName, String lastName) { 12 | this.firstName = firstName; 13 | this.lastName = lastName; 14 | } 15 | 16 | public String getFirstName() { 17 | return firstName; 18 | } 19 | 20 | public void setFirstName(String firstName) { 21 | this.firstName = firstName; 22 | } 23 | 24 | public String getLastName() { 25 | return lastName; 26 | } 27 | 28 | public void setLastName(String lastName) { 29 | this.lastName = lastName; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /framework/rpc-common/src/main/java/com/itjoyee/rpc/common/RpcEncoder.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.common; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.MessageToByteEncoder; 6 | 7 | /** 8 | * RPC 编码器 9 | * 10 | * @author itjoyee 11 | * @since 1.0.0 12 | */ 13 | public class RpcEncoder extends MessageToByteEncoder { 14 | 15 | private Class genericClass; 16 | 17 | public RpcEncoder(Class genericClass) { 18 | this.genericClass = genericClass; 19 | } 20 | 21 | @Override 22 | public void encode(ChannelHandlerContext ctx, Object in, ByteBuf out) throws Exception { 23 | if (genericClass.isInstance(in)) { 24 | byte[] data = SerializationUtil.serialize(in); 25 | out.writeInt(data.length); 26 | out.writeBytes(data); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /framework/rpc-common/src/main/java/com/itjoyee/rpc/common/RpcResponse.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.common; 2 | 3 | /** 4 | * 封装 RPC 响应 5 | * 6 | * @author itjoyee 7 | * @since 1.0.0 8 | */ 9 | public class RpcResponse { 10 | 11 | private String requestId; 12 | private Throwable error; 13 | private Object result; 14 | 15 | public boolean isError() { 16 | return error != null; 17 | } 18 | 19 | public String getRequestId() { 20 | return requestId; 21 | } 22 | 23 | public void setRequestId(String requestId) { 24 | this.requestId = requestId; 25 | } 26 | 27 | public Throwable getError() { 28 | return error; 29 | } 30 | 31 | public void setError(Throwable error) { 32 | this.error = error; 33 | } 34 | 35 | public Object getResult() { 36 | return result; 37 | } 38 | 39 | public void setResult(Object result) { 40 | this.result = result; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/src/test/resources/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/test-classes/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /framework/rpc-common/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /framework/rpc-base-client/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /framework/rpc-base-server/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-sample-client 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc客户端实例 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-compiler-plugin 18 | 19 | 1.7 20 | 1.7 21 | UTF-8 22 | 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-resources-plugin 27 | 28 | UTF-8 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/src/main/resources/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/rpc-sample-client/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-sample-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-sample-client 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc客户端实例 13 | 14 | 15 | 16 | org.apache.maven.plugins 17 | maven-compiler-plugin 18 | 19 | 1.7 20 | 1.7 21 | UTF-8 22 | 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-resources-plugin 27 | 28 | UTF-8 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /framework/rpc-common/src/main/java/com/itjoyee/rpc/common/RpcDecoder.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.common; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.ByteToMessageDecoder; 6 | import java.util.List; 7 | 8 | /** 9 | * RPC 解码器 10 | * 11 | * @author itjoyee 12 | * @since 1.0.0 13 | */ 14 | public class RpcDecoder extends ByteToMessageDecoder { 15 | 16 | private Class genericClass; 17 | 18 | public RpcDecoder(Class genericClass) { 19 | this.genericClass = genericClass; 20 | } 21 | 22 | @Override 23 | public final void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { 24 | if (in.readableBytes() < 4) { 25 | return; 26 | } 27 | in.markReaderIndex(); 28 | int dataLength = in.readInt(); 29 | if (dataLength < 0) { 30 | ctx.close(); 31 | } 32 | if (in.readableBytes() < dataLength) { 33 | in.resetReaderIndex(); 34 | } 35 | byte[] data = new byte[dataLength]; 36 | in.readBytes(data); 37 | 38 | Object obj = SerializationUtil.deserialize(data, genericClass); 39 | out.add(obj); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/src/test/java/com/itjoyee/rpc/sample/app/HelloServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.sample.app; 2 | 3 | import com.itjoyee.rpc.client.RpcProxy; 4 | import com.itjoyee.rpc.sample.client.HelloService; 5 | import com.itjoyee.rpc.sample.client.Person; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @ContextConfiguration(locations = "classpath:spring.xml") 15 | public class HelloServiceTest { 16 | 17 | @Autowired 18 | private RpcProxy rpcProxy; 19 | 20 | @Test 21 | public void helloTest1() { 22 | HelloService helloService = rpcProxy.create(HelloService.class); 23 | String result = helloService.hello("World"); 24 | Assert.assertEquals("Hello! World", result); 25 | } 26 | 27 | @Test 28 | public void helloTest2() { 29 | HelloService helloService = rpcProxy.create(HelloService.class); 30 | String result = helloService.hello(new Person("Yong", "Jiang")); 31 | Assert.assertEquals("Hello! Yong Jiang", result); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /framework/rpc-common/src/main/java/com/itjoyee/rpc/common/RpcRequest.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.common; 2 | 3 | /** 4 | * 封装 RPC 请求 5 | * 6 | * @author itjoyee 7 | * @since 1.0.0 8 | */ 9 | public class RpcRequest { 10 | 11 | private String requestId; 12 | private String className; 13 | private String methodName; 14 | private Class[] parameterTypes; 15 | private Object[] parameters; 16 | 17 | public String getRequestId() { 18 | return requestId; 19 | } 20 | 21 | public void setRequestId(String requestId) { 22 | this.requestId = requestId; 23 | } 24 | 25 | public String getClassName() { 26 | return className; 27 | } 28 | 29 | public void setClassName(String className) { 30 | this.className = className; 31 | } 32 | 33 | public String getMethodName() { 34 | return methodName; 35 | } 36 | 37 | public void setMethodName(String methodName) { 38 | this.methodName = methodName; 39 | } 40 | 41 | public Class[] getParameterTypes() { 42 | return parameterTypes; 43 | } 44 | 45 | public void setParameterTypes(Class[] parameterTypes) { 46 | this.parameterTypes = parameterTypes; 47 | } 48 | 49 | public Object[] getParameters() { 50 | return parameters; 51 | } 52 | 53 | public void setParameters(Object[] parameters) { 54 | this.parameters = parameters; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-zookeeper-registry 10 | 1.0.0-SNAPSHOT 11 | jar 12 | 服务注册和服务发现模块 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-log4j12 18 | 1.7.7 19 | 20 | 21 | 22 | org.apache.zookeeper 23 | zookeeper 24 | 3.4.6 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 33 | 1.7 34 | 1.7 35 | UTF-8 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-resources-plugin 41 | 42 | UTF-8 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-zookeeper-registry/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-zookeeper-registry 10 | 1.0.0-SNAPSHOT 11 | jar 12 | 服务注册和服务发现模块 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-log4j12 18 | 1.7.7 19 | 20 | 21 | 22 | org.apache.zookeeper 23 | zookeeper 24 | 3.4.6 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | 33 | 1.7 34 | 1.7 35 | UTF-8 36 | 37 | 38 | 39 | org.apache.maven.plugins 40 | maven-resources-plugin 41 | 42 | UTF-8 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-sample-server 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc服务端实现实例 13 | 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.11 20 | test 21 | 22 | 23 | 24 | com.itjoyee.rpc 25 | rpc-base-server 26 | 1.0.0-SNAPSHOT 27 | 28 | 29 | 30 | com.itjoyee.rpc 31 | rpc-sample-client 32 | 1.0.0-SNAPSHOT 33 | 34 | 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-compiler-plugin 40 | 41 | 1.7 42 | 1.7 43 | UTF-8 44 | 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-resources-plugin 49 | 50 | UTF-8 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /sample/rpc-sample-server/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-sample-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-sample-server 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc服务端实现实例 13 | 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.11 20 | test 21 | 22 | 23 | 24 | com.itjoyee.rpc 25 | rpc-base-server 26 | 1.0.0-SNAPSHOT 27 | 28 | 29 | 30 | com.itjoyee.rpc 31 | rpc-sample-client 32 | 1.0.0-SNAPSHOT 33 | 34 | 35 | 36 | 37 | 38 | org.apache.maven.plugins 39 | maven-compiler-plugin 40 | 41 | 1.7 42 | 1.7 43 | UTF-8 44 | 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-resources-plugin 49 | 50 | UTF-8 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /framework/rpc-base-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-base-client 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc服务消费基础模块 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-log4j12 18 | 1.7.7 19 | 20 | 21 | 22 | io.netty 23 | netty-all 24 | 4.0.24.Final 25 | 26 | 27 | 28 | com.itjoyee.rpc 29 | rpc-common 30 | 1.0.0-SNAPSHOT 31 | 32 | 33 | 34 | com.itjoyee.rpc 35 | rpc-zookeeper-registry 36 | 1.0.0-SNAPSHOT 37 | 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-compiler-plugin 44 | 45 | 1.7 46 | 1.7 47 | UTF-8 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-resources-plugin 53 | 54 | UTF-8 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /framework/rpc-base-client/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-base-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-base-client 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc服务消费基础模块 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-log4j12 18 | 1.7.7 19 | 20 | 21 | 22 | io.netty 23 | netty-all 24 | 4.0.24.Final 25 | 26 | 27 | 28 | com.itjoyee.rpc 29 | rpc-common 30 | 1.0.0-SNAPSHOT 31 | 32 | 33 | 34 | com.itjoyee.rpc 35 | rpc-zookeeper-registry 36 | 1.0.0-SNAPSHOT 37 | 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-compiler-plugin 44 | 45 | 1.7 46 | 1.7 47 | UTF-8 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-resources-plugin 53 | 54 | UTF-8 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /framework/rpc-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-common 10 | 1.0.0-SNAPSHOT 11 | jar 12 | 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-log4j12 18 | 1.7.7 19 | 20 | 21 | 22 | io.netty 23 | netty-all 24 | 4.0.24.Final 25 | 26 | 27 | 28 | com.dyuproject.protostuff 29 | protostuff-core 30 | 1.0.8 31 | 32 | 33 | com.dyuproject.protostuff 34 | protostuff-runtime 35 | 1.0.8 36 | 37 | 38 | 39 | org.objenesis 40 | objenesis 41 | 2.1 42 | 43 | 44 | 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-compiler-plugin 49 | 50 | 1.7 51 | 1.7 52 | UTF-8 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-resources-plugin 58 | 59 | UTF-8 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /framework/rpc-common/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-common 10 | 1.0.0-SNAPSHOT 11 | jar 12 | 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-log4j12 18 | 1.7.7 19 | 20 | 21 | 22 | io.netty 23 | netty-all 24 | 4.0.24.Final 25 | 26 | 27 | 28 | com.dyuproject.protostuff 29 | protostuff-core 30 | 1.0.8 31 | 32 | 33 | com.dyuproject.protostuff 34 | protostuff-runtime 35 | 1.0.8 36 | 37 | 38 | 39 | org.objenesis 40 | objenesis 41 | 2.1 42 | 43 | 44 | 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-compiler-plugin 49 | 50 | 1.7 51 | 1.7 52 | UTF-8 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-resources-plugin 58 | 59 | UTF-8 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-sample-app 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc应用实例 13 | 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.11 20 | test 21 | 22 | 23 | 24 | org.springframework 25 | spring-context 26 | 3.2.12.RELEASE 27 | 28 | 29 | org.springframework 30 | spring-test 31 | 3.2.12.RELEASE 32 | test 33 | 34 | 35 | 36 | com.itjoyee.rpc 37 | rpc-base-client 38 | 1.0.0-SNAPSHOT 39 | 40 | 41 | 42 | com.itjoyee.rpc 43 | rpc-sample-client 44 | 1.0.0-SNAPSHOT 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-compiler-plugin 52 | 53 | 1.7 54 | 1.7 55 | UTF-8 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-resources-plugin 61 | 62 | UTF-8 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /sample/rpc-sample-app/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-sample-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-sample-app 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc应用实例 13 | 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.11 20 | test 21 | 22 | 23 | 24 | org.springframework 25 | spring-context 26 | 3.2.12.RELEASE 27 | 28 | 29 | org.springframework 30 | spring-test 31 | 3.2.12.RELEASE 32 | test 33 | 34 | 35 | 36 | com.itjoyee.rpc 37 | rpc-base-client 38 | 1.0.0-SNAPSHOT 39 | 40 | 41 | 42 | com.itjoyee.rpc 43 | rpc-sample-client 44 | 1.0.0-SNAPSHOT 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.plugins 51 | maven-compiler-plugin 52 | 53 | 1.7 54 | 1.7 55 | UTF-8 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-resources-plugin 61 | 62 | UTF-8 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /framework/rpc-base-server/src/main/java/com/itjoyee/rpc/server/RpcHandler.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.server; 2 | 3 | import io.netty.channel.ChannelFutureListener; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.SimpleChannelInboundHandler; 6 | 7 | import java.util.Map; 8 | 9 | import net.sf.cglib.reflect.FastClass; 10 | import net.sf.cglib.reflect.FastMethod; 11 | 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.itjoyee.rpc.common.RpcRequest; 16 | import com.itjoyee.rpc.common.RpcResponse; 17 | 18 | /** 19 | * RPC 处理器(用于处理 RPC 请求) 20 | * 21 | * @author itjoyee 22 | * @since 1.0.0 23 | */ 24 | public class RpcHandler extends SimpleChannelInboundHandler { 25 | 26 | private static final Logger LOGGER = LoggerFactory.getLogger(RpcHandler.class); 27 | 28 | private final Map handlerMap; 29 | 30 | public RpcHandler(Map handlerMap) { 31 | this.handlerMap = handlerMap; 32 | } 33 | 34 | @Override 35 | public void channelRead0(final ChannelHandlerContext ctx, RpcRequest request) throws Exception { 36 | RpcResponse response = new RpcResponse(); 37 | response.setRequestId(request.getRequestId()); 38 | try { 39 | Object result = handle(request); 40 | response.setResult(result); 41 | } catch (Throwable t) { 42 | response.setError(t); 43 | } 44 | ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); 45 | } 46 | 47 | private Object handle(RpcRequest request) throws Throwable { 48 | String className = request.getClassName(); 49 | Object serviceBean = handlerMap.get(className); 50 | 51 | Class serviceClass = serviceBean.getClass(); 52 | String methodName = request.getMethodName(); 53 | Class[] parameterTypes = request.getParameterTypes(); 54 | Object[] parameters = request.getParameters(); 55 | 56 | FastClass serviceFastClass = FastClass.create(serviceClass); 57 | FastMethod serviceFastMethod = serviceFastClass.getMethod(methodName, parameterTypes); 58 | return serviceFastMethod.invoke(serviceBean, parameters); 59 | } 60 | 61 | @Override 62 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 63 | LOGGER.error("server caught exception", cause); 64 | ctx.close(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /framework/rpc-base-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-base-server 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc服务提供基础模块 13 | 14 | 15 | 16 | 17 | org.slf4j 18 | slf4j-log4j12 19 | 1.7.7 20 | 21 | 22 | 23 | org.springframework 24 | spring-context 25 | 3.2.12.RELEASE 26 | 27 | 28 | 29 | org.apache.commons 30 | commons-collections4 31 | 4.0 32 | 33 | 34 | 35 | cglib 36 | cglib 37 | 3.1 38 | 39 | 40 | 41 | com.itjoyee.rpc 42 | rpc-common 43 | 1.0.0-SNAPSHOT 44 | 45 | 46 | 47 | com.itjoyee.rpc 48 | rpc-zookeeper-registry 49 | 1.0.0-SNAPSHOT 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-compiler-plugin 57 | 58 | 1.7 59 | 1.7 60 | UTF-8 61 | 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-resources-plugin 66 | 67 | UTF-8 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /framework/rpc-common/src/main/java/com/itjoyee/rpc/common/SerializationUtil.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.common; 2 | 3 | import com.dyuproject.protostuff.LinkedBuffer; 4 | import com.dyuproject.protostuff.ProtostuffIOUtil; 5 | import com.dyuproject.protostuff.Schema; 6 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 7 | import java.util.Map; 8 | import java.util.concurrent.ConcurrentHashMap; 9 | import org.objenesis.Objenesis; 10 | import org.objenesis.ObjenesisStd; 11 | 12 | /** 13 | * 序列化工具类(基于 Protostuff 实现) 14 | * 15 | * @author itjoyee 16 | * @since 1.0.0 17 | */ 18 | public class SerializationUtil { 19 | 20 | private static Map, Schema> cachedSchema = new ConcurrentHashMap<>(); 21 | 22 | private static Objenesis objenesis = new ObjenesisStd(true); 23 | 24 | private SerializationUtil() { 25 | } 26 | 27 | @SuppressWarnings("unchecked") 28 | private static Schema getSchema(Class cls) { 29 | Schema schema = (Schema) cachedSchema.get(cls); 30 | if (schema == null) { 31 | schema = RuntimeSchema.createFrom(cls); 32 | if (schema != null) { 33 | cachedSchema.put(cls, schema); 34 | } 35 | } 36 | return schema; 37 | } 38 | 39 | /** 40 | * 序列化(对象 -> 字节数组) 41 | */ 42 | @SuppressWarnings("unchecked") 43 | public static byte[] serialize(T obj) { 44 | Class cls = (Class) obj.getClass(); 45 | LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE); 46 | try { 47 | Schema schema = getSchema(cls); 48 | return ProtostuffIOUtil.toByteArray(obj, schema, buffer); 49 | } catch (Exception e) { 50 | throw new IllegalStateException(e.getMessage(), e); 51 | } finally { 52 | buffer.clear(); 53 | } 54 | } 55 | 56 | /** 57 | * 反序列化(字节数组 -> 对象) 58 | */ 59 | public static T deserialize(byte[] data, Class cls) { 60 | try { 61 | T message = (T) objenesis.newInstance(cls); 62 | Schema schema = getSchema(cls); 63 | ProtostuffIOUtil.mergeFrom(data, message, schema); 64 | return message; 65 | } catch (Exception e) { 66 | throw new IllegalStateException(e.getMessage(), e); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /framework/rpc-base-server/target/classes/META-INF/maven/com.itjoyee.rpc/rpc-base-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | com.itjoyee.rpc 9 | rpc-base-server 10 | 1.0.0-SNAPSHOT 11 | jar 12 | rpc服务提供基础模块 13 | 14 | 15 | 16 | 17 | org.slf4j 18 | slf4j-log4j12 19 | 1.7.7 20 | 21 | 22 | 23 | org.springframework 24 | spring-context 25 | 3.2.12.RELEASE 26 | 27 | 28 | 29 | org.apache.commons 30 | commons-collections4 31 | 4.0 32 | 33 | 34 | 35 | cglib 36 | cglib 37 | 3.1 38 | 39 | 40 | 41 | com.itjoyee.rpc 42 | rpc-common 43 | 1.0.0-SNAPSHOT 44 | 45 | 46 | 47 | com.itjoyee.rpc 48 | rpc-zookeeper-registry 49 | 1.0.0-SNAPSHOT 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-compiler-plugin 57 | 58 | 1.7 59 | 1.7 60 | UTF-8 61 | 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-resources-plugin 66 | 67 | UTF-8 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /framework/rpc-base-client/src/main/java/com/itjoyee/rpc/client/RpcProxy.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.client; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Proxy; 6 | import java.util.UUID; 7 | 8 | import com.itjoyee.rpc.common.RpcRequest; 9 | import com.itjoyee.rpc.common.RpcResponse; 10 | import com.itjoyee.rpc.registry.ServiceDiscovery; 11 | 12 | /** 13 | * RPC 代理(用于创建 RPC 服务代理) 14 | * 15 | * @author itjoyee 16 | * @since 1.0.0 17 | */ 18 | public class RpcProxy { 19 | 20 | private String serverAddress; 21 | private ServiceDiscovery serviceDiscovery; 22 | 23 | public RpcProxy(String serverAddress) { 24 | this.serverAddress = serverAddress; 25 | } 26 | 27 | public RpcProxy(ServiceDiscovery serviceDiscovery) { 28 | this.serviceDiscovery = serviceDiscovery; 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | public T create(Class interfaceClass) { 33 | return (T) Proxy.newProxyInstance( 34 | interfaceClass.getClassLoader(), 35 | new Class[]{interfaceClass}, 36 | new InvocationHandler() { 37 | @Override 38 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 39 | 40 | RpcRequest request = new RpcRequest(); 41 | request.setRequestId(UUID.randomUUID().toString()); 42 | request.setClassName(method.getDeclaringClass().getName()); 43 | request.setMethodName(method.getName()); 44 | request.setParameterTypes(method.getParameterTypes()); 45 | request.setParameters(args); 46 | 47 | if (serviceDiscovery != null) { 48 | serverAddress = serviceDiscovery.discover(); 49 | } 50 | 51 | String[] array = serverAddress.split(":"); 52 | String host = array[0]; 53 | int port = Integer.parseInt(array[1]); 54 | 55 | // 56 | RpcClient client = new RpcClient(host, port); 57 | RpcResponse response = client.send(request); 58 | 59 | if (response.isError()) { 60 | throw response.getError(); 61 | } else { 62 | return response.getResult(); 63 | } 64 | } 65 | } 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/src/main/java/com/itjoyee/rpc/registry/ServiceRegistry.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.registry; 2 | 3 | import java.io.IOException; 4 | import java.util.concurrent.CountDownLatch; 5 | import org.apache.zookeeper.CreateMode; 6 | import org.apache.zookeeper.KeeperException; 7 | import org.apache.zookeeper.WatchedEvent; 8 | import org.apache.zookeeper.Watcher; 9 | import org.apache.zookeeper.ZooDefs; 10 | import org.apache.zookeeper.ZooKeeper; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | /** 15 | * 服务注册 16 | * 17 | * @author itjoyee 18 | * @since 1.0.0 19 | */ 20 | public class ServiceRegistry { 21 | 22 | private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRegistry.class); 23 | 24 | private CountDownLatch latch = new CountDownLatch(1); 25 | 26 | private String registryAddress; 27 | 28 | /** 29 | * 服务注册类 30 | * @param registryAddress 服务注册的地址 31 | */ 32 | public ServiceRegistry(String registryAddress) { 33 | this.registryAddress = registryAddress; 34 | } 35 | 36 | /** 37 | * 注册服务 38 | * @param serviceName 服务名称 39 | */ 40 | public void register(String serviceName) { 41 | if (serviceName != null) { 42 | // 连接zookeeper 43 | ZooKeeper zk = connectServer(); 44 | if (zk != null) { 45 | // 创建zookeeper节点 46 | createNode(zk, serviceName); 47 | } 48 | } 49 | } 50 | 51 | private ZooKeeper connectServer() { 52 | ZooKeeper zk = null; 53 | try { 54 | zk = new ZooKeeper(registryAddress, Constant.ZK_SESSION_TIMEOUT, new Watcher() { 55 | @Override 56 | public void process(WatchedEvent event) { 57 | if (event.getState() == Event.KeeperState.SyncConnected) { 58 | // 发送时间让阻塞线程继续执行 59 | latch.countDown(); 60 | } 61 | } 62 | }); 63 | // 阻塞当前线程 64 | latch.await(); 65 | } catch (IOException | InterruptedException e) { 66 | LOGGER.error("", e); 67 | } 68 | return zk; 69 | } 70 | 71 | private void createNode(ZooKeeper zk, String data) { 72 | try { 73 | byte[] bytes = data.getBytes(); 74 | String path = zk.create(Constant.ZK_DATA_PATH, bytes, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); 75 | LOGGER.debug("create zookeeper node ({} => {})", path, data); 76 | } catch (KeeperException | InterruptedException e) { 77 | LOGGER.error("", e); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /framework/rpc-base-client/src/main/java/com/itjoyee/rpc/client/RpcClient.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.client; 2 | 3 | import io.netty.bootstrap.Bootstrap; 4 | import io.netty.channel.ChannelFuture; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import io.netty.channel.ChannelInitializer; 7 | import io.netty.channel.ChannelOption; 8 | import io.netty.channel.EventLoopGroup; 9 | import io.netty.channel.SimpleChannelInboundHandler; 10 | import io.netty.channel.nio.NioEventLoopGroup; 11 | import io.netty.channel.socket.SocketChannel; 12 | import io.netty.channel.socket.nio.NioSocketChannel; 13 | 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | import com.itjoyee.rpc.common.RpcDecoder; 18 | import com.itjoyee.rpc.common.RpcEncoder; 19 | import com.itjoyee.rpc.common.RpcRequest; 20 | import com.itjoyee.rpc.common.RpcResponse; 21 | 22 | /** 23 | * RPC 客户端(用于发送 RPC 请求) 24 | * 25 | * @author itjoyee 26 | * @since 1.0.0 27 | */ 28 | public class RpcClient extends SimpleChannelInboundHandler { 29 | 30 | private static final Logger LOGGER = LoggerFactory.getLogger(RpcClient.class); 31 | 32 | private String host; 33 | private int port; 34 | 35 | private RpcResponse response; 36 | 37 | private final Object obj = new Object(); 38 | 39 | public RpcClient(String host, int port) { 40 | this.host = host; 41 | this.port = port; 42 | } 43 | 44 | @Override 45 | public void channelRead0(ChannelHandlerContext ctx, RpcResponse response) throws Exception { 46 | this.response = response; 47 | 48 | synchronized (obj) { 49 | obj.notifyAll(); 50 | } 51 | } 52 | 53 | @Override 54 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { 55 | LOGGER.error("client caught exception", cause); 56 | ctx.close(); 57 | } 58 | 59 | public RpcResponse send(RpcRequest request) throws Exception { 60 | EventLoopGroup group = new NioEventLoopGroup(); 61 | try { 62 | Bootstrap bootstrap = new Bootstrap(); 63 | bootstrap.group(group).channel(NioSocketChannel.class) 64 | .handler(new ChannelInitializer() { 65 | @Override 66 | public void initChannel(SocketChannel channel) throws Exception { 67 | // 对象序列化和反序列化 68 | channel.pipeline() 69 | .addLast(new RpcEncoder(RpcRequest.class)) 70 | .addLast(new RpcDecoder(RpcResponse.class)) 71 | .addLast(RpcClient.this); 72 | } 73 | }) 74 | .option(ChannelOption.SO_KEEPALIVE, true); 75 | 76 | ChannelFuture future = bootstrap.connect(host, port).sync(); 77 | future.channel().writeAndFlush(request).sync(); 78 | 79 | synchronized (obj) { 80 | obj.wait(); 81 | } 82 | 83 | if (response != null) { 84 | future.channel().closeFuture().sync(); 85 | } 86 | return response; 87 | } finally { 88 | group.shutdownGracefully(); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /framework/rpc-zookeeper-registry/src/main/java/com/itjoyee/rpc/registry/ServiceDiscovery.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.registry; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.concurrent.CountDownLatch; 7 | import java.util.concurrent.ThreadLocalRandom; 8 | import org.apache.zookeeper.KeeperException; 9 | import org.apache.zookeeper.WatchedEvent; 10 | import org.apache.zookeeper.Watcher; 11 | import org.apache.zookeeper.ZooKeeper; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | /** 16 | * 服务发现 17 | * 18 | * @author itjoyee 19 | * @since 1.0.0 20 | */ 21 | public class ServiceDiscovery { 22 | 23 | private static final Logger LOGGER = LoggerFactory.getLogger(ServiceDiscovery.class); 24 | 25 | private CountDownLatch latch = new CountDownLatch(1); 26 | 27 | private volatile List dataList = new ArrayList(); 28 | 29 | private String registryAddress; 30 | 31 | public ServiceDiscovery(String registryAddress) { 32 | this.registryAddress = registryAddress; 33 | 34 | ZooKeeper zk = connectServer(); 35 | if (zk != null) { 36 | watchNode(zk); 37 | } 38 | } 39 | 40 | /** 41 | * 发现服务 42 | * @return 43 | */ 44 | public String discover() { 45 | String data = null; 46 | int size = dataList.size(); 47 | 48 | //TODO 可以做软件负载均衡,设置权重,访问权限和访问次数 SOA自治 49 | if (size > 0) { 50 | if (size == 1) { 51 | data = dataList.get(0); 52 | LOGGER.debug("using only data: {}", data); 53 | } else { 54 | data = dataList.get(ThreadLocalRandom.current().nextInt(size)); 55 | LOGGER.debug("using random data: {}", data); 56 | } 57 | } 58 | return data; 59 | } 60 | 61 | private ZooKeeper connectServer() { 62 | ZooKeeper zk = null; 63 | try { 64 | zk = new ZooKeeper(registryAddress, Constant.ZK_SESSION_TIMEOUT, new Watcher() { 65 | @Override 66 | public void process(WatchedEvent event) { 67 | if (event.getState() == Event.KeeperState.SyncConnected) { 68 | latch.countDown(); 69 | } 70 | } 71 | }); 72 | latch.await(); 73 | } catch (IOException | InterruptedException e) { 74 | LOGGER.error("", e); 75 | } 76 | return zk; 77 | } 78 | 79 | private void watchNode(final ZooKeeper zk) { 80 | try { 81 | List nodeList = zk.getChildren(Constant.ZK_REGISTRY_PATH, new Watcher() { 82 | @Override 83 | public void process(WatchedEvent event) { 84 | if (event.getType() == Event.EventType.NodeChildrenChanged) { 85 | watchNode(zk); 86 | } 87 | } 88 | }); 89 | List dataList = new ArrayList<>(); 90 | for (String node : nodeList) { 91 | byte[] bytes = zk.getData(Constant.ZK_REGISTRY_PATH + "/" + node, false, null); 92 | dataList.add(new String(bytes)); 93 | } 94 | LOGGER.debug("node data: {}", dataList); 95 | this.dataList = dataList; 96 | } catch (KeeperException | InterruptedException e) { 97 | LOGGER.error("", e); 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /framework/rpc-base-server/src/main/java/com/itjoyee/rpc/server/RpcServer.java: -------------------------------------------------------------------------------- 1 | package com.itjoyee.rpc.server; 2 | 3 | import io.netty.bootstrap.ServerBootstrap; 4 | import io.netty.channel.ChannelFuture; 5 | import io.netty.channel.ChannelInitializer; 6 | import io.netty.channel.ChannelOption; 7 | import io.netty.channel.EventLoopGroup; 8 | import io.netty.channel.nio.NioEventLoopGroup; 9 | import io.netty.channel.socket.SocketChannel; 10 | import io.netty.channel.socket.nio.NioServerSocketChannel; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | import org.apache.commons.collections4.MapUtils; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | import org.springframework.beans.BeansException; 19 | import org.springframework.beans.factory.InitializingBean; 20 | import org.springframework.context.ApplicationContext; 21 | import org.springframework.context.ApplicationContextAware; 22 | 23 | import com.itjoyee.rpc.common.RpcDecoder; 24 | import com.itjoyee.rpc.common.RpcEncoder; 25 | import com.itjoyee.rpc.common.RpcRequest; 26 | import com.itjoyee.rpc.common.RpcResponse; 27 | import com.itjoyee.rpc.registry.ServiceRegistry; 28 | 29 | /** 30 | * RPC 服务器(用于发布 RPC 服务) 31 | * 32 | * @author itjoyee 33 | * @since 1.0.0 34 | */ 35 | public class RpcServer implements ApplicationContextAware, InitializingBean { 36 | 37 | private static final Logger LOGGER = LoggerFactory.getLogger(RpcServer.class); 38 | 39 | private String serverAddress; 40 | private ServiceRegistry serviceRegistry; 41 | 42 | private Map handlerMap = new HashMap<>(); 43 | 44 | public RpcServer(String serverAddress) { 45 | this.serverAddress = serverAddress; 46 | } 47 | 48 | public RpcServer(String serverAddress, ServiceRegistry serviceRegistry) { 49 | this.serverAddress = serverAddress; 50 | this.serviceRegistry = serviceRegistry; 51 | } 52 | 53 | @Override 54 | public void setApplicationContext(ApplicationContext ctx) throws BeansException { 55 | Map serviceBeanMap = ctx.getBeansWithAnnotation(RpcService.class); 56 | if (MapUtils.isNotEmpty(serviceBeanMap)) { 57 | for (Object serviceBean : serviceBeanMap.values()) { 58 | String interfaceName = serviceBean.getClass().getAnnotation(RpcService.class).value().getName(); 59 | handlerMap.put(interfaceName, serviceBean); 60 | } 61 | } 62 | } 63 | 64 | @Override 65 | public void afterPropertiesSet() throws Exception { 66 | // 创建netty 67 | EventLoopGroup bossGroup = new NioEventLoopGroup(); 68 | EventLoopGroup workerGroup = new NioEventLoopGroup(); 69 | try { 70 | ServerBootstrap bootstrap = new ServerBootstrap(); 71 | bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) 72 | .childHandler(new ChannelInitializer() { 73 | @Override 74 | public void initChannel(SocketChannel channel) throws Exception { 75 | channel.pipeline() 76 | .addLast(new RpcDecoder(RpcRequest.class)) 77 | .addLast(new RpcEncoder(RpcResponse.class)) 78 | .addLast(new RpcHandler(handlerMap)); 79 | } 80 | }) 81 | .option(ChannelOption.SO_BACKLOG, 128) 82 | .childOption(ChannelOption.SO_KEEPALIVE, true); 83 | 84 | String[] array = serverAddress.split(":"); 85 | String host = array[0]; 86 | int port = Integer.parseInt(array[1]); 87 | 88 | ChannelFuture future = bootstrap.bind(host, port).sync(); 89 | LOGGER.debug("server started on port {}", port); 90 | 91 | //注册服务 92 | if (serviceRegistry != null) { 93 | serviceRegistry.register(serverAddress); 94 | } 95 | 96 | future.channel().closeFuture().sync(); 97 | } finally { 98 | workerGroup.shutdownGracefully(); 99 | bossGroup.shutdownGracefully(); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 分布式 RPC 框架 2 | 3 | 4 | ### 单一应用架构 5 | ![image](https://github.com/jiajianfa/rcp/blob/master/dubbo1.jpg) 6 | 当网站流量很小时,只需一个应用,将所有功能都部署在一起,以减少部署节点和成本。 7 | 此时,用于简化增删改查工作量的 数据访问框架(ORM) 是关键。 8 | 9 | ### 垂直应用架构 10 | 当访问量逐渐增大,单一应用增加机器带来的加速度越来越小,将应用拆成互不相干的几个应用,以提升效率。 11 | 此时,用于加速前端页面开发的 Web框架(MVC) 是关键。 12 | 13 | ### 分布式服务架构 14 | 当垂直应用越来越多,应用之间交互不可避免,将核心业务抽取出来,作为独立的服务,逐渐形成稳定的服务中心,使前端应用能更快速的响应多变的市场需求。 15 | 此时,用于提高业务复用及整合的 分布式服务框架(RPC) 是关键。 16 | 17 | ### 流动计算架构 18 | ![image](https://github.com/jiajianfa/rcp/blob/master/dubbo2.jpg) 19 | 当服务越来越多,容量的评估,小服务资源的浪费等问题逐渐显现,此时需增加一个调度中心,基于访问压力实时管理集群容量,提高集群利用率。 20 | 此时,用于提高机器利用率的 资源调度和治理中心(SOA) 是关键。 21 | 22 | 在大规模服务化之前,应用可能只是通过RMI或Hessian等工具,简单的暴露和引用远程服务,通过配置服务的URL地址进行调用,通过F5等硬件进行负载均衡。 23 | 24 | (1) 当服务越来越多时,服务URL配置管理变得非常困难,F5硬件负载均衡器的单点压力也越来越大。 25 | 此时需要一个服务注册中心,动态的注册和发现服务,使服务的位置透明。 26 | 并通过在消费方获取服务提供方地址列表,实现软负载均衡和Failover,降低对F5硬件负载均衡器的依赖,也能减少部分成本。 27 | 28 | (2) 当进一步发展,服务间依赖关系变得错踪复杂,甚至分不清哪个应用要在哪个应用之前启动,架构师都不能完整的描述应用的架构关系。 29 | 这时,需要自动画出应用间的依赖关系图,以帮助架构师理清理关系。 30 | 31 | (3) 接着,服务的调用量越来越大,服务的容量问题就暴露出来,这个服务需要多少机器支撑?什么时候该加机器? 32 | 为了解决这些问题,第一步,要将服务现在每天的调用量,响应时间,都统计出来,作为容量规划的参考指标。 33 | 其次,要可以动态调整权重,在线上,将某台机器的权重一直加大,并在加大的过程中记录响应时间的变化,直到响应时间到达阀值,记录此时的访问量,再以此访问量乘以机器数反推总容量。 34 | 35 | (4) 规模继续扩大,应用之间不再是扁平的对应关系,开始分层,比如核心数据层,业务集成层等,就算没有出现循环依赖,也不允许从低层向高层依赖,以免后续被逼循环依赖。 36 | 这时,需要在注册中心定义架构体系,列明有哪些层的定义,每个服务暴露或引用时,都必须声明自己应用属于哪一层,这样注册中心能更快的发现架构的腐化现象。 37 | 38 | (5) 服务多了,沟通成本也开始上升,调某个服务失败该找谁?服务的参数都有什么约定? 39 | 这时就需要登记每个服务都是谁负责的,并建立一个服务的文档库,方便检索。 40 | 41 | (6) 慢慢一些敏感数据也都服务化了,安全问题开始变得重要,谁能调该服务?如何授权? 42 | 43 | 这样的服务可能需要一个密码,访问时需带着此密码,但如果用密码,要改密码时,就会很不方便,所有的消费方都要改,所以动态生成令牌(Token)可能会更好,提供方将令牌告之注册中心,由注册中心决定是否告之消费方,这样就能在注册中心页面上做复杂的授权模型。 44 | 45 | (7) 就算是不敏感的服务,也不是能任意调用,比如某服务突然多了一个消费者,这个消费者的请求量直接把服务给拖跨了,其它消费者跟着一起故障。 46 | 首先服务提供方需要流控,当流程超标时,能拒绝部分请求,进行自我保护。 47 | 其次,消费者上线前和提供者约定《服务质量等级协定(SLA)》,SLA包括消费者承诺每天调用量,请求数据量,提供方承诺响应时间,出错率等,将SLA记录在监控中心,定时与监控数据对比,超标则报警。 48 | 49 | (8) 虽然有SLA约定,如果不能控制,就只是君子协定,如何确保服务质量? 50 | 比如:一个应用很重要,一个不那么重要,它们调用同一个服务,这个服务就应该向重要应用倾斜,而不是一视同仁,当支撑不住时,应限制不重要应用的访问,保障重要应用的可用,如何做到这一点呢。这时,就需要服务路由,控制不同应用访问不同机器,比如: 51 | 应用分离: 52 | consumer.application = foo => provider.host = 1,2,3 53 | consumer.application != foo => provider.host = 5,6 54 | 读写分离: 55 | method.name = find*,get* => provider.host = 1,2,3 56 | method.name != find*,get* => provider.host = 5,6 57 | 58 | (9) 服务上线后,需要验证服务是否可用,但因防火墙的限制,线下是不能访问线上服务的,不得不先写好一个测试Main,然后放到线上去执行,非常麻烦,并且容易忘记验证。 59 | 所以线上需要有一个自动运行的验证程序,用户只需在界面上填上要验证的服务方法,以及参数值和期望的返回值,当有一个服务提供者上线时,将自动运行该用例,并将运行结果发邮件通知负责人。 60 | 61 | (10)服务应用和Web应用是有区别的,它是一个后台Daemon程序,不需要Tomcat之类的Web容器。但因公司之前以Web应用为主,规范都是按Web应用的,所以不得不把服务跑在一个根本用不上的Web容器里,而搭一个这样的Web工程也非常费事。 62 | 所以需要实现一个非Web的容器,只需简单的Main加载Spring配置即可,并提供Maven模板工程,只需mvn dubbo:generate 即可创建一个五脏俱全的服务应用。 63 | 64 | (11) 开发服务的人越来越多,更注重开发效率,IDE的集成支持必不可少。 65 | 通过插件,可以在Eclipse中直接运行服务,提供方可以直接填入测试数据测试服务,消费方可以直接Mock服务不依赖提供方开发。 66 | 67 | (12) 因为暴露服务很简单,服务的上线越来越随意,有时候负责服务化的架构师都不知道有人上线了某个服务,使得线上服务鱼龙混杂,甚至出现重复的服务,而服务下线比上线还困难。 68 | 需要一个新服务上线审批流程,必须经过服务化的架构师审批过了,才可以上线。 69 | 而服务下线时,应先标识为过时,然后通知调用方尽快修改调用,直到没有人调此服务,才能下线。 70 | 71 | (13) 因服务接口设计的经验一直在慢慢的积累过程中,很多接口并不能一促而蹴,在修改的过程中,如何保证兼容性,怎么判断是否兼容?另外,更深层次的,业务行为兼容吗? 72 | 可以根据使用的协议类型,分析接口及领域模型的变更是否兼容,比如:对比加减字段,方法签名等。 73 | 而业务上,可能需要基于自动回归测试用例,形成Technology Compatibility Kit (TCK),确保兼容升级。 74 | 75 | (14)随着服务的不停升级,总有些意想不到的事发生,比如cache写错了导致内存溢出,故障不可避免,每次核心服务一挂,影响一大片,人心慌慌,如何控制故障的影响面?服务是否可以功能降级?或者资源劣化? 76 | 应用间声明依赖强度,哪些功能强依赖,哪些弱依赖,然后基于依赖强度,计算出影响面,并定期测试复查,加强关键路径上的服务的优化和容错,清理不该在关键路径上的服务。 77 | 提供容错Mock数据,Mock数据也应可以在注册中心在运行时动态下发,当某服务不可用时,用Mock数据代替,可以减少故障的发生,比如某验权服务,当验权服务全部挂掉后,直接返回false表示没有权限,并打印Error日志报警。 78 | 另外,前端的页面也应采用Portal进行降级,当该Portal获取不到数据时,直接隐藏,或替换为其它模块展示,并提供功能开关,可人工干预是否展示,或限制多少流量可以展示。 79 | 80 | (15) 当已有很多小服务,可能就需要组合多个小服务的大服务,为此,不得不增加一个中间层,暴露一个新服务,里面分别调其它小服务,这样的新服务业务逻辑少,却带来很多开发工作量。 81 | 此时,需要一个服务编排引擎,内置简单的流程引擎,只需用XML或DSL声明如何聚合服务,注册中心可以直接下发给消费者执行聚合逻辑,或者部署通用的编排服务器,所有请求有编排服务器转发。 82 | 83 | (16) 并不是所有服务的访问量都大,很多的服务都只有一丁点访问量,却需要部署两台提供服务的机器,进行HA互备,如何减少浪费的机器。 84 | 此时可能需要让服务容器支持在一台机器上部署多个应用,可以用多JVM隔离,也可以用ClassLoader隔离。 85 | 86 | (17) 多个应用如果不是一个团队开发的,部署在一台机器上,很有可以误操作,停掉了别人的服务。 87 | 所以需要实现自动部署,所有的部署都无需人工干扰,最好是一键式部署。 88 | 89 | (18) 机器总是的闲时和忙时,或者冗余机器防灾,如何提高机器的利用率? 90 | 即然已经可以自动部署了,那根据监控数据,就可以实现资源调度,根据应用的压力情况,自动添加机器并部署。 91 | 如果你的应用是国际化的,有中文站,美国站之类,因为时差,美国站的机器晚上闲的时候,可能正是中文站的白天忙时,可以通过资源调度,分时段自动调配和部署双方应用。 92 | 按关键词归纳为: 93 | 94 | 1. 服务注册与发现 95 | 96 | 2. 软负载均衡与容错 97 | 98 | 3. 服务监控与统计 99 | 100 | 4. 服务容量评估 101 | 102 | 5. 服务上线审批 103 | 104 | 6. 服务下线通知 105 | 106 | 7. 服务负责人 107 | 108 | 8. 服务文档 109 | 110 | 9. 服务路由 111 | 112 | 10. 服务编排 113 | 114 | 11. 服务黑白名单 115 | 116 | 12. 服务权限控制 117 | 118 | 13. 服务依赖关系 119 | 120 | 14. 服务分层架构 121 | 122 | 15. 服务调用链跟踪 123 | 124 | 16. 故障传导分析 125 | 126 | 17. 服务降级 127 | 128 | 18. 服务等级协定 129 | 130 | 19. 服务自动测试 131 | 132 | 20. 服务伪装容错 133 | 134 | 21. 服务兼容性检测 135 | 136 | 22. 服务使用情况报告 137 | 138 | 23. 服务权重动态调整 139 | 140 | 24. 服务负载均衡调整 141 | 142 | 25. 服务映射 143 | 144 | 26. 服务模板工程 145 | 146 | 27. 服务开发IDE 147 | 148 | 28. 服务健康检测 149 | 150 | 29. 服务容器 151 | 152 | 30. 服务自动部署 153 | 154 | 31. 服务资源调度 155 | 156 | 157 | ## 技术选型 158 | (http://my.oschina.net/huangyong/blog/361751) 159 | 160 | 1. 依赖注入:Spring 3.2.12 161 | 2. 数据传输:Netty 4.0.24 162 | 3. 序列化:Protostuff 1.0.8 163 | 4. 服务注册:ZooKeeper 3.4.6 164 | 165 | ## 使用方法 166 | 167 | 1. 启动 ZooKeeper 服务器(测试时可在本地启动)。使用命令行客户端创建 168 | 2. 运行`rpc-sample-server`模块中的`RpcBootstrap`类,启动 RPC 服务器。 169 | 3. 运行`rpc-sample-app`模块中的`HelloServiceTest`单元测试,查看测试是否通过。 170 | 171 | ## 相关配置 172 | 173 | 1. 服务端配置:打开`rpc-sample-server`模块中的`rpc.properties`文件,可配置`ZooKeeper 地址`与`RPC 服务器地址`。 174 | 2. 客户端配置:打开`rpc-sample-app`模块中的`rpc.properties`文件,可配置`ZooKeeper 地址`。 175 | 176 | ## TODO 177 | 178 | 179 | 180 | 181 | --------------------------------------------------------------------------------