If you want to send messages from one machine to another and not worry about callbacks, then Redis pub / sub is the best solution. It is really easy to implement, and Redis is very fast.
First you need to install Redis on one of your machines.
It is really easy to connect to Redis:
var client = require('redis').createClient(redis_port, redis_host);
But do not forget about opening the Redis port in your firewall!
Then you need to subscribe to each machine on some channel:
client.on('ready', function() { return client.subscribe('your_namespace:machine_name'); }); client.on('message', function(channel, json_message) { var message; message = JSON.parse(message);
You can skip your_namespace and use the global namespace, but you'll regret it soon.
It is also very easy to send messages:
var send_message = function(machine_name, message) { return client.publish("your_namespace:" + machine_name, JSON.stringify(message)); };
If you want to send different types of messages, you can use pmessages instead of messages:
client.on('ready', function() { return client.psubscribe('your_namespace:machine_name:*'); }); client.on('pmessage', function(pattern, channel, json_message) { // pattern === 'your_namespace:machine_name:*' // channel === 'your_namespace:machine_name:'+message_type var message = JSON.parse(message); var message_type = channel.split(':')[2]; // do whatever you want with the message and message_type }); send_message = function(machine_name, message_type, message) { return client.publish([ 'your_namespace', machine_name, message_type ].join(':'), JSON.stringify(message)); };
It is best practice to name your processes (or machines) their functionality (for example, 'send_email' ). In this case, a process (or machine) can be subscribed to more than one channel, if it implements several functionality.
In fact, you can build bidirectional communication using redis. But this is more complicated, because for each request it is necessary to add a unique callback channel name in order to receive a callback without losing context.
So, my conclusion is this: Use Redis if you need to "send and forget" a message, explore other solutions if you need a full bi-directional communication .