oneRPC
I want to exercise my network programming and engineering design ability by writing an RPC framework, and this project is also my school project of this semester. The code was posted on GitHub and I wanted to write something to record what I learned during the implementation process. I also enjoyed sharing my insights with others. (My Java language)
Making: github.com/onemsg/oneR…
The blog has a start today and will be updated in detail later
Train of thought
-
I don’t have a lot of project/internship experience, I haven’t actually used any RPC framework, I’ve read articles about RPC and dubbo’s introductory case. So, when I first felt like writing, I searched a lot of RPC introduction (infoQ, Zhihu, blog, gRPC website). After reading these materials, I had a general design direction in mind: which transport protocol should I choose, TCP or HTTP? What serialization protocol do I choose? Search a lot of Java related protocols, to understand one by one and compare.
-
At the beginning, I chose TCP and Kryo. Vertx used by TCP server/client was found to be difficult to write. TCP needed to define its own application layer protocol and unpack what was very troublesome. Kryo isn’t easy to use either.
-
Following the principle of “minimizing viable products”, I abandoned the original TCP + Kryo solution and chose HTTP + MSgpack. The HTTP server uses Vertx, the client uses JDK11 HttpClient, and msgpack uses -Jakson. The implementation is much smoother this time. I also used Maven’s multi-module development for the first time, including client, core, Server, Registry and Example. Module decoupling.
-
After the client calls the server implementation, thinking that all RPC frameworks have service discovery function, it uses ETCD to do service discovery. Well, ETCD does work better than ZK, but embarrassingly, I implemented one RPC and used another (ETCD’s Java client communicates with the server using gRPC).
harvest
-
The minimum viable product idea is very useful. It encourages you to build a working product quickly and then optimize and iterate, which is very useful for completing a project from scratch.
-
Jackson’s ObjectMapper, when serializing a json string such as “[1,2,3,4]” into a Java object, will be serialized as a List
object by default if it is not explicitly specified. New int[]{1,2,3,4}. ObjectMapper serializes the pojo as a json string. Deserialize to a Java object, where the poJO’s value type is List
.
-
Learn and write more Unit testing so that you can quickly and repeatedly test your code changes.
todo …