Thursday, November 11, 2010

Thrift_Example

Just want to share the new Technology info…… known as Thrift.

Thrift is a software framework for scalable cross-language services development. It 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, Smalltalk, and OCaml.

Inshort !! now we can expose any method written in any above specified language and can consume it by creating client (again with any specified language)

One Billion $ Question !! How to use Thrift 

First download thrift-incubating-0.2.0.tar.gz [PGP] [MD5]

http://incubator.apache.org/thrift/download/

then create jar libthrit.jar need to use Both client and Server.

Use attached Thrift.zip to have Thrift exe for win M/C.

step 1) Extract thrift-0.2.0 folder or .gz file in linux.

step 2) Go to folder /thrift-0.2.0/lib/java

cd /thrift-0.2.0/lib/java

step 3) Change the JAVA_HOME (link it to latest JAVA Version installed in linux) and use jdk1.6.0_20

export $JAVA_HOME=/jdk1.6.0_20

step 4) use Apache ant to create jar (as ant use directly ivy.xml to create libthrit.jar) – run below given command
/apache-ant-1.8.1/bin/ant


=====Steps to create client and server in JAVA using Thrift technology.

1) Create .thrift file.

2) Create glue code using this command C:\Thrift\thrift --gen java "name of the thrift file created above i.e. xyz.thrift".

i.e. C:\Thrift\thrift --gen java time.thrift

3) Create an *Impl file that implement the interface created on step 2.

4) Create Server file.

5) Create Client file.

6) Run Server file first.

7) Run Client file to get the output.

Note : 1) For reference please refer to the attached Thrift_example containing both example
(a) JAVA Client and JAVA Server.
(b) JAVA Client and Perl Server.


===Step to use Thrift for creating Perl as server and JAVA as client

Step 1) Write .thrift file

Step 2) Create JAVA Interface using this command C:\Thrift\thrift --gen java "name of the thrift file created above i.e. xyz.thrift".
i.e. C:\Thrift\thrift --gen java testPerl.thrift

Step 3) Create Server code using Thrift Perl Command

C:\Test\Thrift_Example>C:\Thrift\thrift --gen perl testPerl.thrift

Step 4) Run Perl Server file

C:\SpringSource_Workspace\Thrift_Example\src>perl PerlServer.pl

Step 5) Run java Client

No comments: