Hello fellow Alchemist,
Our current web API is build monolithic rails style, and i’m starting to toy around with a Umbrella Elixir project, for starters it’s gonna replace some of our listing features, which Elixir/Poison does 100x times faster, and ultimately the entire api.
But while in the transitioning phase, i’m wondering what the easiest way is to communicate with the Elixir project, from the Rails server.
Was wondering something like rabbitmq, or maybe just a simple Plug server, would just be happy if could exclude the option of another http call .
What are your thoughts? Is it possible to connect to a GenServer from a Ruby project? Or something alike?
I would suggest going the other way around and using terraform.
Its an awesome library that routes unimplemented endpoints from phoenix to another application.
If you are not going to use phoenix and just want an elixir service rabbitmq probably is the way to go, but you could also try tcp sockets.
I’m not using Phoenix, i’m prolly gonna make a sub project featuring a web endpoint with Plug or Phoenix, but right now, i would actually rather spend my time on adding more features :). I just can’t help but feel that another HTTP call is unnecessary, then again, if it’s the fastest to setup, it might be the way to go :).
Thx for your feedback vasspilka .
Note that TCP is not HTTP, HTTP is build on top of TCP/IP. Many modern applications communicate over TCP and it can be fast without much overhead. You would have to find a common interface though, (could be json or maybe binary?). Also for realtime or streaming connections there is UDP but I guess its harder to implement.
But you are right HTTP is the most simple one both to reason about and to implement (I guess because we use it often and have familiarized with it).
Another solution I’ve heard of but never actually saw any examples is to run the whole rails project from inside otp, but I guess its quite risky unless you absolutely know what you are doing things will most likely go wrong.
::EDIT:: The last one is not really a solution as you just execute ruby code not communicate between apps but is you are interested here are some resources: erlport ruby and blogpost for elixir
Use Phoenix as a reverse proxy and route all Rails calls through your Phoenix Project, while re-implementing them in Phoenix one by one. This ensures that your app does not break and you can focus on one call at a time.
Example implementation: https://blog.fourk.io/replace-your-production-api-with-elixir-today-4426a8903642#.tw34zily8
If you want to go with the umbrella approach, you can do something that I did. I had an internal API written in Node.js, and now wanted to work on the WebApp in Phoenix. Created an umbrella app, with two sub-apps; The Phoenix one, and a GenServer that simply spawns the node app on boot.
Mix method 1 and 2 up!