What's the best way to make one node.js server "talk" to another?
- MsgPack ?
- JSON-RPC ?
- Socket.io (is it possible ? how 开发者_开发知识库?)
EDIT: I am talking about 2 node processes each one on a different physical machine;
I don't understand how redis can help me on this...
I'm not really clear on whether you are looking for ways to make two node servers on two physical machines "talk to each other", or two node.js server processes on one machine.
(You could edit your question to make it clearer).
You could look at:
- protocol buffers for node
- MsgPack-RPC for node
- Websocket.MQ
- dnode --This uses socket.io as the transport layer
- IPCNode
- AMQP with node-amqp or node-amqp and something like RabbitMQ
- Or you could go with a document based db like redis
Note: some of these may need some updating
I hope this helps
I would go for redis. The pubsub semantics are pretty sweet. The node_redis client library is very fast because it can use the lightning fast c-extension-library named hiredis. I would just use json as my encoding. That will probably be more than fast enough.
You could also use DNode to do your communication if you like. I also believe it has socket.io capabilities. You should have a look at the source code to find this out.
It is not really clear from your question what do you mean by a Node server talking to another server. You can use anything from sending UDP packets, making TCP connections, HTTP connections to using any of the high-level mechanisms that others have already pointed out.
For an interesting scenerio of Node processes communication you may take a look at the 2010 JSConf.eu talk by Mikeal Rogers. He explains how to use CouchDB to do that. Very interesting talk.
精彩评论