5

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?

Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115
xjq233p_1
  • 7,810
  • 11
  • 61
  • 107

2 Answers2

4

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.

Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115
  • 3
    To add to this, do consider zeromq if you want an ecosystem where it has to be langauge agnostic - where different processes written in different languages are to communicate with each other over a standardized protocol. That is what zeromq can provide - simplify the communication layer and make it really easy for processes to talk to each other. – Ruben Tan Jun 15 '12 at 04:43
3

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

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

Arbind Thakur
  • 344
  • 3
  • 5