Skip to content

Commit

Permalink
Refer to topics, rather than queues.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Mar 27, 2014
1 parent bf9495f commit b79343b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
24 changes: 12 additions & 12 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var app = exports = module.exports = {};
configurable(app);

app.init = function() {
this.queue = '';
this.topic = '';
this.settings = {};
this._stack = [];
this._router = new Router();
Expand All @@ -34,28 +34,28 @@ app.defaultConfiguration = function(){
});
};

app.use = function(queue, fn) {
if ('string' != typeof queue) {
fn = queue;
queue = '';
app.use = function(topic, fn) {
if ('string' != typeof topic) {
fn = topic;
topic = '';
}

// wrap sub-apps
if ('function' == typeof fn.handle) {
var server = fn;
server.queue = queue;
server.topic = topic;
fn = function(msg, next) {
server.handle(msg, next);
};
}

// add the middleware
debug('use %s %s', queue || '#', fn.name || 'anonymous');
this._stack.push({ queue: queue, handle: fn });
debug('use %s %s', topic || '#', fn.name || 'anonymous');
this._stack.push({ topic: topic, handle: fn });
return this;
}

app.work = function(queue) {
app.work = function(topic) {
var args = [].slice.call(arguments);

// if no router attached yet, attach the router
Expand Down Expand Up @@ -93,11 +93,11 @@ app.handle = function(msg, out) {
}

try {
// skip this layer if the queue doesn't match, noting that queue names are
// skip this layer if the topic doesn't match, noting that topic names are
// case sensitive
if (0 != msg.queue.indexOf(layer.queue)) return next(err);
if (0 != msg.topic.indexOf(layer.topic)) return next(err);

debug('%s %s', layer.handle.name || 'anonymous', layer.queue);
debug('%s %s', layer.handle.name || 'anonymous', layer.topic);
var arity = layer.handle.length;
if (err) {
if (arity == 3) {
Expand Down
10 changes: 5 additions & 5 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ var pattern = require('urlpattern').express;
*
* @api protected
*/
function Route(queue, fns, options) {
function Route(topic, fns, options) {
options = options || {};
this.queue = queue;
this.topic = topic;
this.fns = fns;
this.regexp = pattern.parse(queue
this.regexp = pattern.parse(topic
, this.keys = []
, options.sensitive
, options.strict);
}

Route.prototype.match = function(queue, params) {
Route.prototype.match = function(topic, params) {
params = params || [];

var keys = this.keys
, m = this.regexp.exec(queue);
, m = this.regexp.exec(topic);

if (!m) return false;

Expand Down
18 changes: 9 additions & 9 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function Router() {
};
}

Router.prototype.route = function(queue, fns) {
Router.prototype.route = function(topic, fns) {
var fns = utils.flatten([].slice.call(arguments, 1));

// ensure queue was given
if (queue === undefined) throw new TypeError('Router.route() requires a queue');
// ensure topic was given
if (topic === undefined) throw new TypeError('Router.route() requires a topic');

// ensure all handlers are functions
fns.forEach(function(fn, i){
Expand All @@ -37,8 +37,8 @@ Router.prototype.route = function(queue, fns) {
});

// create the route
debug('defined %s', queue);
var route = new Route(queue, fns, {
debug('defined %s', topic);
var route = new Route(topic, fns, {
sensitive: this.caseSensitive,
strict: this.strict
});
Expand All @@ -49,7 +49,7 @@ Router.prototype.route = function(queue, fns) {
};

Router.prototype._dispatch = function(msg, next) {
debug('dispatching %s (%s)', msg.queue, msg.originalQueue);
debug('dispatching %s (%s)', msg.topic, msg.originalTopic);

var self = this;

Expand All @@ -62,7 +62,7 @@ Router.prototype._dispatch = function(msg, next) {
var route = self._match(msg, i);
if (!route) { return next(err); }

debug('matched %s', route.queue);
debug('matched %s', route.topic);

// invoke route callbacks
var idx = 0;
Expand All @@ -88,7 +88,7 @@ Router.prototype._dispatch = function(msg, next) {
}

Router.prototype._match = function(msg, i) {
var queue = msg.queue
var topic = msg.topic
, routes = this.arr
, route
, i = i || 0;
Expand All @@ -97,7 +97,7 @@ Router.prototype._match = function(msg, i) {
// matching routes
for (var len = routes.length; i < len; ++i) {
route = routes[i];
if (route.match(queue, msg.params = [])) {
if (route.match(topic, msg.params = [])) {
return route;
}
}
Expand Down

0 comments on commit b79343b

Please sign in to comment.