Browse files

ditching ZeroMQ in favour of Redis Pub / Sub

  • Loading branch information...
1 parent 8f57035 commit bef7baff8a06c5fc61e3aa9177a92e776d1b2e48 @makeusabrew committed Aug 23, 2011
Showing with 17 additions and 19 deletions.
  1. +13 −11 goursome.js
  2. +4 −8 server.js
View
24 goursome.js
@@ -6,9 +6,8 @@ var util = require('util'),
path = process.argv[2],
namespace = process.argv[3],
http = require('http'),
- zeromq = require('zeromq');
-
-var socket = zeromq.createSocket('sub');
+ redis = require('redis'),
+ sub = redis.createClient();
try {
process.chdir(path);
@@ -18,16 +17,19 @@ try {
process.exit(1);
}
-socket.subscribe(namespace);
+sub.subscribe(namespace);
process.stderr.write('subscribed to channel ['+namespace+']\n');
-socket.connect("tcp://127.0.0.1:5556");
-
-socket.on('message', function(data) {
- var decoded = data.toString().split(" ");
- var msg = JSON.parse(decoded[1]);
- updateLog(msg.oldrev, msg.newrev, function(code) {
- process.stderr.write('Updated ['+msg.namespace+'] git repository\n');
+sub.on('message', function(channel, message) {
+ var data = null;
+ try {
+ data = JSON.parse(message);
+ } catch (e) {
+ process.stderr.write("Could not decode publisher message ["+message+"]");
+ return;
+ }
+ updateLog(data.oldrev, data.newrev, function(code) {
+ process.stderr.write('Updated ['+data.namespace+'] git repository\n');
});
});
View
12 server.js
@@ -4,13 +4,8 @@ var util = require('util'),
spawn = require('child_process').spawn,
querystring = require('querystring'),
http = require('http'),
- zeromq = require('zeromq');
-
-var socket = zeromq.createSocket('pub');
-socket.bind("tcp://127.0.0.1:5556", function(err) {
- if (err) throw err;
- console.log('bound ZeroMQ pub socket');
-});
+ redis = require('redis'),
+ pub = redis.createClient();
http.createServer(function(req, res) {
// simply listen out for POST requests
@@ -25,7 +20,8 @@ http.createServer(function(req, res) {
if (postvars.namespace && postvars.oldrev && postvars.newrev) {
console.log('sending refs ['+postvars.oldrev+'] .. ['+postvars.newrev+'] to channel ['+postvars.namespace+']');
- socket.send(postvars.namespace+' '+JSON.stringify(postvars));
+ //socket.send(postvars.namespace+' '+JSON.stringify(postvars));
+ pub.publish(postvars.namespace, JSON.stringify(postvars));
res.writeHead(200, {'Content-Type' : 'text/plain'});
res.end('OK\n');
} else {

0 comments on commit bef7baf

Please sign in to comment.