Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to structure communication between Nodejs server and rails?

I am currently using rails to serve static web pages and I am experimenting with NodeJs to handle some real time aspect of my application.

I have been able to have do a one way communication between Nodejs to my Rails server by having Nodejs write to a db and my rails server reading from it.

Now I want to do the other way, aka an action in Rails will trigger an action in Nodejs. Obviously I can be dumb and have a node continually polling the database server.

What are my options?

  1. Set up RPC calls between both
  2. Set up a TCP socket both ways

Are there easier/quicker options?

like image 605
disappearedng Avatar asked Feb 19 '12 20:02

disappearedng


2 Answers

Well technically you got a lot of ways for inter process communication, if you want something easy I believe you should have a look at dnode which provides RPC on TCP or named pipes and it has a ruby implementation. Making it very easy for you to do RPC calls and since it is TCP you can use it cross machines.

You can also have a message queue such zeromq, but I believe that will have unnecessary overhead. It would be good for cases that you have much more than two process talking to each other.

Beside all these if you want the minimum latency, if you're processes are both running on one machine, I believe you should use a named pipe and stdio for communication, but I don't know any module in node that will help you to abstract that, and you have to build your own RPC module on stdio.

like image 112
Farid Nouri Neshat Avatar answered Sep 28 '22 18:09

Farid Nouri Neshat


If you are using redis, I recently wrote a redis_message_capsule:

  • ruby gem
  • node npm package

to do this. Feel free to try it out or modify it as you like.

like image 42
Arbind Thakur Avatar answered Sep 28 '22 19:09

Arbind Thakur