Permalink
Browse files

Release v0.2.1 - Bug fixes and refactoring

v0.2.1
* Majorly refactored code
* Added autoIndexId: true to queue collection creation
* Better MongoMQ application with help()
* Updated test application
* Added an exception to emit() when you try to emit before start() has
been called
* fix to onAny so it will restart listeners after a close() and start()
re-issue
* Added remove*() methods
* Changed close() to stop()
* hereOnOut options - allows listeners to only pay attention to messages
posted after they have been started up
* Added ability to register listeners (via on and onAny) when queue is
not started
  • Loading branch information...
jdarling committed Jul 17, 2012
1 parent a6bd9e0 commit 5669f5e277dfd344bab0622105df4d395b80774d
Showing with 766 additions and 180 deletions.
  1. +24 −3 bin/MongoMQ.js
  2. +48 −20 bin/test.js
  3. +0 −1 lib/MongoConnection.js
  4. +317 −108 lib/MongoMQ.js
  5. +181 −0 lib/MongoMQ_bu.js
  6. +1 −1 package.json
  7. +195 −47 readme.md
View
@@ -23,13 +23,14 @@ var r = repl.start({
});
r.on('exit', function(){
- queue.close();
+ queue.stop(); // force a close
});
-var funcName, value;
+var funcName, value, funcs = [];
for(funcName in queue){
value = queue[funcName];
if(typeof(value)=='function'){
+ funcs.push(funcName);
r.context[funcName] = (function(f){
return function(){
f.apply(queue, arguments);
@@ -45,4 +46,24 @@ r.context.logAny = function(){
});
};
-r.context.queue = queue;
+r.context.help = function(){
+ msg = 'Built in test methods:\r\n'+
+ ' help() - shows this message\r\n'+
+ ' logAny() - logs any message to the console\r\n'+
+ ' listeners() - Alias of the queue.listeners property surfaced as a method\r\n';
+ var l = funcs.length;
+ for(var i = 0; i<l; i++){
+ msg += ' '+funcs[i]+'() - Alias of the queue.'+funcs[i]+' method\r\n';
+ }
+ msg += '\r\nInstance Data\r\n'+
+ ' queue - the global MongoMQ instance\r\n'
+ ;
+ console.log(msg);
+ return '';
+};
+
+r.context.listeners = function(){
+ return queue.listeners;
+};
+
+r.context.queue = queue;
View
@@ -1,23 +1,17 @@
var MongoMQ = require('../lib/MongoMQ').MongoMQ;
var repl = require('repl');
-var queue = new MongoMQ();
+var queue = new MongoMQ({
+ autoStart: false
+});
var r = repl.start({
- prompt: ">"
+ prompt: "testbed>"
});
-
r.on('exit', function(){
- queue.close();
+ queue.stop();
});
-r.context.listen = function(){
- queue.on('test', function(err, data, next){
- console.log('got: ', data);
- next();
- });
-};
-
var msgidx = 0;
r.context.send = function(){
queue.emit('test', msgidx);
@@ -31,18 +25,52 @@ r.context.load = function(){
}
};
+var logMsg = function(err, data, next){
+ console.log('LOG: ', data);
+ next();
+ };
+var eatTest = function(err, data, next){
+ console.log('eat: ', data);
+ next();
+ };
+
r.context.logAny = function(){
- queue.onAny(function(err, data, next){
- console.log(data);
- next();
- });
+ queue.onAny(logMsg);
};
r.context.eatTest = function(){
- queue.on('test', function(err, data, next){
- console.log('eat: ', data);
- next();
- });
+ queue.on('test', eatTest);
+};
+
+r.context.start = function(cb){
+ queue.start(cb);
};
-r.context.queue = queue;
+r.context.stop = function(){
+ queue.stop();
+};
+
+r.context.help = function(){
+ console.log('Built in test methods:\r\n'+
+ ' help() - shows this message\r\n'+
+ ' logAny() - logs any message to the console\r\n'+
+ ' eatTest() - consumes next available "test" message from the queue\r\n'+
+ ' send() - places a "test" message on the queue\r\n'+
+ ' load() - places 100 "test" messages on the queue\r\n'+
+ ' start() - start the queue listener\r\n'+
+ ' stop() - stop the queue listener\r\n'+
+ '\r\nInstance Data\r\n'+
+ ' queue - the global MongoMQ instance\r\n'
+ );
+ return '';
+};
+
+/*
+queue.start(function(){
+ r.context.eatTest();
+});
+*/
+
+r.context.queue = queue;
+
+r.context.help();
View
@@ -3,7 +3,6 @@ var key;
for(key in mongodb){
if(hasOwnProperty.call(mongodb, key)){
- //console.log('Importing: ', key);
global[key] = exports[key] = mongodb[key];
}
}
Oops, something went wrong.

0 comments on commit 5669f5e

Please sign in to comment.