Using Facebook Thrift

While I am looking for a general RPC solution, Thrift comes to my eyes. It is now an Apache project although developed at Facebook. Thrift is very similar to Google’s protocol buffer, which was open sourced and hosted on Google Code. For me, Thrift seems support more languages and deployed with a whole set of surrounding support, including thread manager and server/client stubs. More interestingly, Thrift supports exception, that is, exceptions thrown by remote methods can be caught by client code. (I do not remember that Google protocol buffer support this ….)

However, Thrift does not yet have an official tutorial, so, here is a very brief one. (I would resort to an official one once it is published.)

  1. Download Thrift from
  2. Unpack the .tar.gz file to create /tmp/thrift-0.2.0
  3. Configure, build and install
    ./configure --prefix=~/wyi/thrift-0.2.0 CXXFLAGS='-g -O2'
    make install
  4. Generate source code from tutorial.thrift
    cd tutorial
    ~wyi/thrift/bin/thrift -r --gen cpp tutorial

    Note that the -r flag indicates generating also include files. The result source code will be placed into a sub-directory named gen-cpp.

  5. Compile example C++ server and client programs in tutorial/cpp
    cd cpp

    Note that you might want to change the Makefile to tell the lib and include directories where Thrift was installed.