官术网_书友最值得收藏!

Apache Thrift

Thrift is a project created by Facebook and maintained by the Apache Software Foundation. It has a good level of compatibility with the languages most commonly used in the market of programming.

Thrift has the communication layer with RPC and a part of serialization using a file .thrift as a template. The file .thrift has notation and types similar to the C++ language in which Thrift was developed.

An example of file .thrift can be viewed in the following:

    typedef i32 MyInteger 
 
    const i32 INT32CONSTANT = 9853 
    const map<string,string> MAPCONSTANT = {'hello':'world', 
'goodnight':'moon'} enum Operation { ADD = 1, SUBTRACT = 2, MULTIPLY = 3, DIVIDE = 4 } struct Work { 1: i32 num1 = 0, 2: i32 num2, 3: Operation op, 4: optional string comment, } exception InvalidOperation { 1: i32 whatOp, 2: string why } service Calculator extends shared.SharedService { void ping(), i32 add(1:i32 num1, 2:i32 num2), i32 calculate(1:i32 logid, 2:Work w) throws
(1:InvalidOperation ouch), oneway void zip() }

Do not worry about the file contents. The important thing is realizing the flexibility that is offered by the RPC Thrift composition. An interesting point to note is the following line of code:

    service Calculator extends shared.SharedService { ...  

Thrift allows the use of inheritance among the template files, which will be used by code generators.

To create the client/server using Thrift, simply use the following command line:

   $ thrift -r --gen py file_name.thrift  

The preceding line will create a client and server in the Python programming language.

Among the options presented, the most common at the moment are Thrift and gRPC, and any one of these tools is a good deployment option for direct communication between microservices.

主站蜘蛛池模板: 巴塘县| 临湘市| 龙南县| 德兴市| 桦甸市| 永胜县| 筠连县| 错那县| 洱源县| 渑池县| 集贤县| 博乐市| 浦城县| 涞源县| 宁德市| 毕节市| 永康市| 额济纳旗| 旬邑县| 阿拉善左旗| 镇沅| 友谊县| 南通市| 泰州市| 重庆市| 汉寿县| 凤阳县| 盘锦市| 韶山市| 乌拉特后旗| 景德镇市| 井冈山市| 漾濞| 德昌县| 广昌县| 镇康县| 盘锦市| 全椒县| 天镇县| 张家港市| 临城县|