The best approach really depends on how tightly you want to integrate. Some possible integration points:

 1. you want to call thrift services from rails controllers
2. you want thrift services to be called by convention when you call certain railsy methods on your objects
 3. you want to replace your database calls with calls to thrift services
 4. you want to pass rails objects into thrift services

#1 is pretty straightforward, and #2 can be accomplished through mixins. #3 requires a framework (I developed a framework I call activethrift about a year ago to be able to do this plus #4 and a lot more. We ended up using it with merb, as merb makes it easier to pick and choose which pieces you want which ones, like ActiveRecord, you can simply drop. If you're interested, we should talk more offline about what it'll take to open source ActiveThrift and what documentation is needed, since it uses a lot of convention -- kind of the rails way, though).

The way I would accomplish #4 would be through a thrift client adapter. I would pass in my rails object to a thrift client wrapper, that would then use reflection to convert the rails object into the equivalent thrift object. It would create an object of the expected (thrift) type, then It would look through the struct_fields of the expected type, and set each field of the thrift object wherever the passed in object respond_to? that field.

A better way would probably be to mixin a conversion method (to_thrift) on the rails object, and simply call this in the adapter.

Cheers,
Ben

Hi again all,

A general architecture question regarding the usage of Thrift within a Rails application. What are the best practices for integration of Thrift in this environment? Has anyone done so? So far I have managed to use Rack with success, but was curious if anyone has come up with a tighter integration scenario.

Thanks,
Chris

Reply via email to