- Microservice Patterns and Best Practices
- Vinicius Feitosa Pacheco
- 283字
- 2021-06-30 19:02:55
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.
- Mastering Node.js(Second Edition)
- 物聯網智慧安監技術
- 電子政務效益的經濟分析與評價
- TCP/IP入門經典(第5版)
- 新一代物聯網架構技術:分層算力網絡
- Getting Started with WebRTC
- Mastering Dart
- Learning Windows 8 Game Development
- 網絡綜合布線(第2版)
- Learning Node.js Development
- 一本書讀懂物聯網
- 異構蜂窩網絡關鍵理論與技術
- 云計算技術與標準化
- ReasonML Quick Start Guide
- Hands-On Cloud:Native Microservices with Jakarta EE