Skip to content

Commit

Permalink
ditching ZeroMQ in favour of Redis Pub / Sub
Browse files Browse the repository at this point in the history
  • Loading branch information
makeusabrew committed Aug 23, 2011
1 parent 8f57035 commit bef7baf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
24 changes: 13 additions & 11 deletions goursome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
});
});

Expand Down
12 changes: 4 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit bef7baf

Please sign in to comment.