Search code examples
web-servicesthrift

Can I have discoverable services using Apache Thrift?


The goal would be to have discoverable thrift servers that can compute things, specifically I would like to know what services they have and what are the ttypes for the parameters those services need. Ideally all I would need to know is the IP and port of the server and be able to get back all this information before I use it.

Let's say the server has the following service:

service Calculator {
   double add(1:double num1, 2:double num2),
   double subtract(1: double num1, 2:double num2),
   double sqrt(1:double num1)
}

By just having the IP and port, is it possible to know this server has these three methods, and how many variables each one takes and of what type?


Solution

  • Thrift does not provide an service location framework infrastructure (think WADL), simply because this is (at least currently) out of scope for Thrift. Despite that, one has a number of options indeed.

    1. Publishing the Thrift IDL file(s) as HTTP-downloadable items, like Evernote does.

    2. Using thrift -gen html yourfile.thrift to generate a nice HTML page containing a fully fledged description of everything what's in the IDl file, including any /** docstyle comments */ you made. The result looks very similar to the Evernote API Reference, except that the layout has improved somewhat in the meantime.