Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Commit

Permalink
Added try catch to Queen rabbit stuff so if an bad message comes through
Browse files Browse the repository at this point in the history
it won't explode
  • Loading branch information
Tehsmash committed Nov 14, 2013
1 parent 57ce97b commit 902f543
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
15 changes: 10 additions & 5 deletions Queen/rabbit/rabbit_pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ function onQueueCreateOk(exchange, routingKey, callback) {

function onMessage(callback) {
return function(message, headers, deliveryInfo) {
console.log("Message Received! Parsing...");
var msg = message['data'].toString('utf-8');
console.log(msg);
console.log(JSON.parse(msg));
callback(JSON.parse(msg));
try {
console.log("Message Received! Parsing...");
var msg = message['data'].toString('utf-8');
console.log(msg);
console.log(JSON.parse(msg));
callback(JSON.parse(msg));
} catch(err) {
console.log("There was an error: " + err);
return
}
}
}
21 changes: 13 additions & 8 deletions Queen/rabbit/rabbit_rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ exports.RPCQuery = function (queueName, data, callback) {
connection.queue('', {exclusive: true}, function (queue) {
self.responseQueue = queue.name;
queue.subscribe(function (message, headers, deliveryInfo, m) {
if (self.correlationId === m.correlationId) {
clearTimeout(timeout);
connection.end();
var msg = message['data'].toString('utf-8');
console.log('Parsing Response...');
console.log(msg);
callback(JSON.parse(msg));
try {
console.log(message)
if (self.correlationId === m.correlationId) {
clearTimeout(timeout);
connection.end();
var msg = message['data'].toString('utf-8');
console.log('Parsing Response...');
console.log(msg);
callback(JSON.parse(msg));
}
} catch(err) {
console.log("Some Error Occured: " + err);
return
}
console.log(message);
});

connection.publish(queueName, data, {
Expand Down

0 comments on commit 902f543

Please sign in to comment.