Introduction to Apache Thrift

Hello readers,

Firstly, let me begin with a brief definition of Apache Thrift, it is a software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages. Instead of writing a load of boilerplate code to serialize and transport your objects and invoke remote methods, you can get right down to business.

Architecture

Thrift includes a complete stack for creating clients and servers. The top part is generated code from the Thrift definition. The services generate from this file client and processor code. In contrast to built-in types, created data structures are sent as result in generated code. The protocol and transport layer are part of the runtime library. With Thrift, it is possible to define a service and change the protocol and transport without recompiling the code. Besides the client part, Thrift includes server infrastructure to tie protocols and transports together, like blocking, non-blocking, and multi-threaded servers. The underlying I/O part of the stack is differently implemented for different languages.

1

Installation of Apache Thrift

 First install the dependencies and then you are ready to install Thrift.

Install the languages with which you plan to use thrift. To use with Java for example, install a Java JDK you prefer and check if is installed on the system.

Install JAVA:

$ sudo apt-get install openjdk-8-jdk -y

$ java -version

 java-version

To use  Java you will also need to install Apache ant

$ sudo apt-get install ant

 ant.png

 

Install required tools and libraries:

 Ubuntu

$ sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev

CentOS5/Rhel5

$ sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel

 1

 1) Download apache thrift version 0.9.0 rather than 0.9.1

 

 T1.png 

 2) Copy the downloaded file into the desired directory and untar the file

 2

$ tar -xvf thrift-0.9.0.tar.gz

3) Build Thrfit according to instructions – Update PKG_CONFIG_PATH in bashrc by typing the following command in terminal:

$ sudo nano ~/.bashrc

  • paste the following line at the end

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/hduser/hadoop/thrift-0.9.0/lib/cpp

  • Then source the bashrc via

source ~/.bashrc

  • Verifiy pkg-config path is correct: Type this in terminal

# pkg-config –cflags thrift

-I/usr/local/include/thrift

  • Copy Thrift library sudo cp /usr/local/lib/libthrift-0.9.0 /usr/lib/

 I.png

4) Get some core development tools that are not direct dependencies below

$ sudo apt-get install git-core make

5) The following pulls in openjdk-6-jre-headless to provide /usr/bin/java:

$ sudo apt-get install maven2

3

6)  Pull in the main thrift dependencies

4

$ sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev

7) Add curl since we’ll need it shortly:

$ sudo apt-get install curl

 5

8) Python is enabled by default (although broken since there is no Python.h header). This line will build with C++ and Java:

$ cd thrift-0.9.0

$ ./configure –prefix=/usr –without-python JAVA_PREFIX=/usr/share/java

9) Build:

3

$ make

7

10) Install:

$ sudo make install

After the execution of this command, Apache Thrift will be installed in the system. I had to install thrift for installing rhbase on my Ubuntu system as thrift is the main dependency of rhbase for building services. But, you can install thrift whenever there is need to build services between languages such as C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, etc.

Thank you for Reading.

 

References :

 [1] https://thrift.apache.org/

[2] https://en.wikipedia.org/wiki/Apache_Thrift

[3] http://thrift-tutorial.readthedocs.io/en/latest/intro.html

[4] https://thrift.apache.org/docs/install/debian

[5] http://www.thrift.pl/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s