Thrift that little thing.

Source: Internet
Author: User
thrift that little thing.

This blog post is not thrift enlightenment and Hello World, please take a detour if necessary thrift official website
Http://thrift.apache.org, but aims to thrift after the completion of indefinitely a collation and summary. I hope to help the students who are in this dire stage. Use of Thrift Thrift's Five great King Kong Facebook's Swift Use of Thrift

Since we have already preliminary study of Thrift,thrift in the end is what also probably know, the most powerful is the cross-lingual RPC, and I learn this is mainly the company's internal distribution service is the main mode of transmission is thrift. There may be classmates to compare with Dubbo these, in fact, thrift itself in the distribution of no advantage, it does not like Dubbo as there is a registration center, service discovery and some monitoring. Thrift is by defining a common service (thrift file) that is described in its own language, and then providing-gen to generate various languages to build services and invoke services. Thrift Five King Kong five King Kong is my own set, there is no related to the Internet, just to facilitate their memory API and familiar with the process. The five great King Kong were: Transport Protocol Processor Client tserver Transport Transport Layer

Main two dimensions: server and client

The parent class of the server Tservertransport,
Divided into blocking tserversocket and non-blocking tnonblockingtransport (this is an abstract class, the implementation is Tnonblockingserversocket).
So from the implementation point of view are xxserversocket, so good to remember.

The parent class of the client is Ttransport, which is also blocked and non-blocking,
There are different transmission forms, such as tsocket for socket programming, and Thttpclient is the HTTP protocol transmission, Tfiletransport is the file transfer.
Here the Tsocket is synchronous blocking, that is, the traditional Io, and tframetransport is synchronous non-blocking, equivalent to NiO, and Tnonblockingtransport is asynchronous non-blocking, equivalent to AIO. The latter two are non-blocking, so they have to correspond to the server Tnonblockingservertransport protocol protocol

The Protocol of the transmission, the protocol provided in thrift is not many, mainly divided into two kinds: text transmission (such as JSON, compact compression) and binary transmission (binary).
It's easy to wonder and confuse, and to emphasize that, whether it's text transfer or binary transmission, they will eventually be converted to the corresponding binary byte based on the encoding they set, such as UTF-8, and then transferred.
That... What is the difference between the two? The only difference between text transfer and binary transmission is the handling of newline characters. Binary is regardless, and the text (the reason that the text is to see, of course, to deal with line breaks) to handle newline characters according to the operating system by default encoding, under UNIX is 2 bytes, but in DOS is 4 bytes, when using such as FTP download file, Converting to a different operating system automatically adds or removes 2 bytes based on the system code. So text content between different operations must be transmitted with text, because the binary is not to be converted at all, then to different operating systems will not be recognized. If it is for binary files, such as pictures, videos, executables, you must use binary transmission, imagine your own picture in the other system with a few bytes added ... (⊙o⊙) ... You're sure you can use it. Of course, all this is done on the basis of different operating systems, and over the same operating system, there will be no such confusion Processor

processors, in thrift automatically generated Java files, Iface,client and processor are the most important static inner classes. This processor is the service side in the implementation of the specific interface logic, and then when the server started to tell the servers, this interface to deal with this. Therefore, this client does not need to be used at all. Client

Client... So the server doesn't have to be here at all. This is used when the client invokes the service, and the internal method contains all of the methods that we define in the interface, so the client passes the corresponding parameters and invokes them directly on the clients. Tserver

This is also the service side of the party, and tservertransport corresponding, in fact, is a combination of processor+transport+protocol, is to forcibly put these three together to use, provide services to the outside Tserver.serve (); The main has three tserver:tsimpleserver single-threaded blocking IO, this is also tested there playing tthreadserver multithreading blocking IO tnonblockingserver This course is multithreaded non-blocking IO Facebook's Swift

A code cleanliness may be uncomfortable thrift automatically generated that nearly thousands of lines of Java files, and in the programming of the transmission structure is not very clear, often to go back to see the thrift file. So you can use Facebook's Open source project, Swift, to improve on thrift, use annotations like @thriftserver, @ThriftStruct to describe a Java object, and also provide a MAVEN plugin that can be generated automatically.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.