Thrift cross-service development framework and thrift development framework
Thrift Overview
Thrift is a software framework used to develop scalable and cross-language services. It integrates powerful software stacks and code generation engines to build in C ++, Java, Python, PHP,
Ruby, Erlang, Perl, Haskell, C #, Cocoa, JavaScript, Node. js, Smalltalk, and OCaml are seamlessly integrated and efficient services.
Code generation tool command: "thrift-*. exe"-r-gen java./*. thrift generate gen-java directory
1. Basic Steps for server encoding:
* Implement service processing interface impl
* Create TProcessor // read and write
* Create a TServerTransport
* Create a TProtocol
* Create a TServer
* Start Server
2. Client encoding steps:
* Create a Transport
* Create a TProtocol
* Create a Client based on TTransport and TProtocol
* Call the corresponding Client Method
3. Data Transmission Protocol
* TBinaryProtocol: binary format.
* TCompactProtocol: compression format
* TJSONProtocol: JSON format
* TSimpleJSONProtocol: Provides JSON write-only protocol, and the generated files are easily parsed using the script language.
4. Server
* TSimpleServer single-thread mode test
* TNonblockingServer NIO selector loop listener
* THsHaServer uses a separate thread to process network I/O, and an independent worker thread pool to process messages
* TThreadedSelectorServer is non-blocking and multiple threads are used to process network I/O. It maintains two thread pools, one for network I/O processing and the other for request processing.
* The TThreadPoolServer uses the blocking socket method. The main thread is responsible for blocking listening to "listening for socket" to see if there are new sockets. The business processing is handled by a thread pool.
Project address: https://github.com/windwant/thrifttest