Giter Site home page Giter Site logo

yeecode / easyrpc Goto Github PK

View Code? Open in Web Editor NEW
568.0 10.0 184.0 367 KB

EasyRPC是一个远程过程调用(Remote Procedure Call,简称RPC)的最小实现。它使用极少的类、方法演示了RPC的实现原理,是一个学习RPC工作原理的良好示例。

License: Apache License 2.0

Java 100.00%
rpc easyrpc rpc-framework remote-procedure-call demo

easyrpc's Introduction

language license

EasyRPC是一个远程过程调用(Remote Procedure Call,简称RPC)的最小实现。它使用极少的类、方法演示了RPC的实现原理,是一个学习RPC工作原理的良好示例。

该项目十分简单,包括客户端EasyRpcClient和服务端EasyRpcServer两部分。演示时,EasyRpcClient会通过RPC调用EasyRpcServer中的方法。

功能演示

/client/target/文件夹下下载最新版的EasyRpcClient-x.x.x.jar文件,并使用下面的命令启动:

java -jar EasyRpcClient-x.x.x.jar

则EasyRpcClient启动,并工作在12310端口。

/server/target/文件夹下下载最新版的EasyRpcServer-x.x.x.jar文件,并使用下面的命令启动:

java -jar EasyRpcServer-x.x.x.jar

则EasyRpcServer启动,并工作在12311端口。

然后可以调用以下几个方法:

  • 127.0.0.1:12310/getUserCount
  • 127.0.0.1:12310/getUserInfo
  • 127.0.0.1:12310/addUser
  • 127.0.0.1:12310/querySchoolName

上面几个方法会被则EasyRpcClient接收。然后,EasyRpcClient会通过RPC调用EasyRpcServer获得操作结果,并返回。

功能实现

EasyRpcClient实现

业务代码类为MainControllerSchoolServiceUserService三个类。其中MainController类负责接收外部请求并调用SchoolServiceUserServiceSchoolServiceUserService是两个接口,并不包含实现,其具体实现由EasyRpcServer提供。

RPC代码类在rpc子包中,主要完成动态代理、远程调用参数序列化、远程调用发起、远程调用结果反序列化等工作。

EasyRpcClient代码

EasyRpcServer实现

业务带代码类为SchoolServiceUserService两个类,类中包含具体实现。EasyRpcClient通过RPC最终调用了这里的代码。

RPC代码类在rpc子包中,主要完成远程调用接收、调用参数反序列化、调用实际触发、调用结果序列化等工作。

EasyRpcServer代码

easyrpc's People

Contributors

dependabot[bot] avatar yeecode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easyrpc's Issues

看了知乎回答过来的,请教几个问题

1、客户端是什么时候从服务端拿到函数映射列表的?

2、客户端组装好数据后,通过什么样的方式序列化数据?需要跟着服务端的规定来做吗?

比如:前端浏览器环境,我是序列化成 json 呢?还是用 form-url-encode ?还是有其它方式?

因为有的文章说的神乎其神的,还要二进制打包啥的,完全不知道他们要表述什么。

3、客户端用 POST 还是 GET 请求的方式?也是跟着服务端的规定来吗?

4、服务端处理完数据后,传给前端的数据格式,跟我们平常请求接口返回的数据格式是一样的吗?

有个关于返回类型的疑问

在client的ServiceProxy中的invoke代码中看到

return JSON.parseObject(result.getResultValue(), Class.forName(result.getResultType()));

假设client没有server对应的返回值类型该怎么样呢?

I met this build problem, when use order "mvn clean install -Prelease" to build this proj

[INFO] Not executing Javadoc as the project is not a Java classpath-capable package
[INFO]
[INFO] --- maven-gpg-plugin:1.6:sign (default) @ EasyRPC ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.20/plexus-utils-3.0.20.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.20/plexus-utils-3.0.20.pom (3.8 kB at 1.4 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.pom (3.0 kB at 2.7 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.20/plexus-utils-3.0.20.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar (28 kB at 12 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.20/plexus-utils-3.0.20.jar (243 kB at 15 kB/s)
gpg: directory '/home/panda/.gnupg' created
gpg: keybox '/home/panda/.gnupg/pubring.kbx' created
gpg: no default secret key: No secret key
gpg: signing failed: No secret key
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for EasyRPC 0.0.1:
[INFO]
[INFO] EasyRPC ............................................ FAILURE [04:46 min]
[INFO] EasyRpcClient ...................................... SKIPPED
[INFO] EasyRpcServer ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:46 min
[INFO] Finished at: 2024-04-28T14:26:19Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign (default) on project EasyRPC: Exit code: 2 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.