Thrift Generalization Client

Source: Internet
Author: User
Thrift Generalization Client One, Pain point

When using thrift, you must compile the generated client code that supports the thrift protocol based on the IDL file. Once a new service is added, the client program must recompile and update the online service to dynamically invoke the new service.
Ii. Solutions 2.1 Mainly solves two problems:

1. Description Information of data structure
2. A thrift client that can be used universally
2.2 Description Information of data structure

It is well known that thrift is cross-platform and cannot provide a generalization client and server like Dubbo, and must be converted according to the format of IDL definition. So, to implement a class generalization client, we need to abstract the description information, and there is intermediate media (I am using MySQL), once there is a new service, only the structure description information written to the intermediary media, the generalization client can be invoked.

Description Information Entity:

As pictured, used to describe a thrift object. And this tree structure can describe the hierarchical relationship of this object clearly (for example, a struct, there may be a multi-layer relationship).


It is a general structure that describes all the information related to the service. Call the method name of the specific method, the entry parameter, and the entry parameter, the argument description information 2.3 A thrift client that can be generalized

We know that the thrift underlying transport protocol, although there are many, but it is the data in order to form a packet, we only know the order of the packet, and dynamically obtain the description information, we can construct and parse the transmission of data.
Thrift Packet Description (relatively simple, there are some details inside)

Once you can get descriptive information and find out the parsing rules, we can construct a generalization client.
Write:
Based on the Java generalization client, all transmission data is object, according to the description information into the specific thrift type data, according to a certain transport protocol sent to the client
read:
To follow the description information to traverse the acquired packets, And eventually a JSON object is constructed and returned to the caller.
This project supports both synchronous and asynchronous calls
GitHub address: https://github.com/waj89757/generic-thrift-client

Related Article

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.