Search code examples
filterthriftsession-management

Management layer above Thrift


Thrift sounds awesome but can't find some basic stuff I'm used to in RPC frameworks (as HttpServlet). Example of the things I can't find: session management, filtering, upload/download progress.

I understand that the missing stuff might be a management layer on top of Thrift. If so, any example of such a layer? Perhaps AOP (Aspect Oriented)?

I can't imagine such a layer that compiles to all languages and that's I'm missing. Taking session management as an example, there might be several clients that all need to do some authentication and pass the session_id upon each RPC. I would expect a similar API for all languages doing so.

Anyone knows of a a management layer for Thrift?


Solution

  • So thrift itself is not going to help you out a lot here. I have had similar desires, and have a few suggestions:

    1. Put your management objects into the IDL

    Simply add an api token or common transfer data struct as a parameter to all of your service methods. Set it as parameter id 15 so that it will always be the last parameter, even if you add others in the middle.

    As the first step in your handler you can validate/store/do whatever with the extra data.

    This has the advantage that it is valid in any platform that thrift supports.

    2. Use thrift over http

    If you use http as your transport, you can include whatever data as you want as http headers, and the thrift content as the body.

    This will often require a custom http client for every platform you use to inject the data, and a custom handler on the server to use the data, but neither of those are prohibitively difficult.

    3. Hack the protocol

    It is possible to create your own custom protocol that wraps another protocol and injects custom data. Take a look at how the multiplexed protocol works in the thrift library for most languages: c# here. It sends the method name across the wire as service:method. The multiplexed processor unwraps this encoding and passes it on to the appropriate processor.

    I have used a similar method to encode arbitrary key/value pairs (like http headers) inside the method name.

    The downside to this is that you need to write a more complicated extension for each platform you will be using. Once. It varies a bit from language to language how this works, but it is generally simple enough once you figure it out once.


    These are just a few ideas I have had, and I am sure there are others. The nice thing about thrift is how the individual components are decoupled from each other. If you have special needs you can swap any of them out as you need to to add specific functionality.