Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining a clojure app with a Ruby on Rails app

I have a Clojure back-end that I want to put a Rails front-end to. How should I connect them, and how specifically do I do it?

Off the top of my head, there are two ways:

  • run Jruby on rails, in the same process as the clojure app
  • run normal Ruby on Rails, and connect it to the clojure backend through a message queue, web hooks, and through a joint DB.

Both seem to have disadvantages. In the former, it seems that running jruby will limit the gems we can reuse and otherwise cost us productivity when library authors have not made something perfectly compatible. In the latter, I imagine we'll miss out on code reuse - possibly having to implement the same thing twice in some cases - and that the more complicated interfaces (web hooks instead of just function calls for example) will cost us.

Finally, in the case of JRuby, it's unclear how to actually connect the two. Both come with management scripts: rake and leiningen, and specific repository layouts. I don't really how to start joining them together. Advise and war stories welcome.

like image 639
Paul Biggar Avatar asked Nov 05 '22 11:11

Paul Biggar


2 Answers

I think if it were me, I'd definitely use message queues to communicate between those services—though JRuby really is a good choice on the front-end as well (I think most gems are fairly compatible at this point, even those with native extensions.) Ultimately, you can use elements of both approaches.

What you're talking about is a fairly typical SOA set up, and that's one of the great things about SOA—you can leverage different languages and platforms where they do best. Trying to use clojure within a jruby-on-rails setup is likely to lead to much pain and misery, and IIRC it'll taint some of the benefits of using clojure in the first place.

Unfortunately I don't have any war stories that precisely match up to what you're trying to do, but I'm in the middle of such an architecture right now and its working out great, using RabbitMQ to let MRI 1.9 talk to backend workers running JRuby. Not sure how you'd consume messages in clojure, but I imagine there's got to be docs on it somewhere, and you'll be able to maintain clean separation. If you were to run your front end on jruby, you can still share code between the jruby process and clojure backend without having to put them in the same process.

like image 152
Keith Gaddis Avatar answered Nov 09 '22 06:11

Keith Gaddis


I haven't done anything yet with Clojure + JRuby, but I have tried out JRuby + Scala/Java.

Scala/Java side works as the service layer and JRuby on Rails sits on top of it. Both projects are managed separately: Scala/Java project is compiled via Maven into a JAR which is then added as a dependency to the Rails application.

This seems to work quite nicely and I guess Clojure would work even better, because Clojure collections implement the interfaces that JRuby consumes, in Scala I had to tweak the service layer interfaces.

like image 20
ponzao Avatar answered Nov 09 '22 05:11

ponzao