Problems worthy of attack prove their worth by hitting back. —Piet Hein

Friday, 28 September 2007

A Java Servlet for Thrift

I've been playing around with Thrift (the new version that came out a few days ago), mainly to see how it might be used as a serialization mechanism in Hadoop, but also because the RPC looks useful. It doesn't come with a Java HTTP server transport, so I whipped up a servlet to make it easy. Exposing a service is then as simple as subclassing the base servlet to supply a Thrift processor to service the request. For the calculator example from the tutorial:
package server;

import tutorial.Calculator;

public class CalculatorTServlet extends TServlet {
public CalculatorTServlet() {
super(new Calculator.Processor(new CalculatorHandler()));

Invoking the service is easy - you just use the THttpClient transport. Using Thrift over HTTP allows you to use all your existing high-availability and failover infrastructure, which can be attractive. (But also see this Thrift mailing list thread which gives some more detail on how Facebook tackles high-availability and failover.)


Soma said...


This is pretty cool. It has been 3 years, since you posted this. Have you used this in a practical applications? Any experiences you can share?


greyfairer said...

Hi there,

Since this is the only reference found by google, and the link is outdated, I decided to save fellow searchers the extra trouble and point directly to:

And the history: