servicebus
Advanced tools
Comparing version 0.2.5 to 0.3.0
function Bus () { | ||
this.middleware = []; | ||
this.incomingMiddleware = []; | ||
this.outgoingMiddleware = []; | ||
} | ||
Bus.prototype.use = function (middleware) { | ||
this.middleware.push(middleware); | ||
if (middleware.handleIncoming) this.incomingMiddleware.push(middleware.handleIncoming); | ||
if (middleware.handleOutgoing) this.outgoingMiddleware.push(middleware.handleOutgoing); | ||
return this; | ||
} | ||
Bus.prototype.handleIncoming = function (message, headers, deliveryInfo, messageHandle, options, callback) { | ||
var stack = this.middleware, index = this.middleware.length - 1; | ||
var stack = this.incomingMiddleware, index = this.incomingMiddleware.length - 1; | ||
@@ -27,12 +28,7 @@ function next (err) { | ||
if ( ! layer) { | ||
if ( undefined === layer) { | ||
return callback(message, headers, deliveryInfo, messageHandle, options); | ||
} | ||
if (layer.handleIncoming) { | ||
layer.handleIncoming(message, headers, deliveryInfo, messageHandle, options, next); | ||
} else { | ||
next(null, message, headers, deliveryInfo, messageHandle, options); | ||
layer(message, headers, deliveryInfo, messageHandle, options, next); | ||
} | ||
} | ||
@@ -43,6 +39,5 @@ | ||
Bus.prototype.handleOutgoing = function (queueName, message, callback) { | ||
var stack = this.middleware, index = 0; | ||
var stack = this.outgoingMiddleware, index = 0; | ||
@@ -61,11 +56,7 @@ function next (err) { | ||
if ( ! layer) { | ||
if ( undefined === layer) { | ||
return callback(queueName, message); | ||
} | ||
if (layer.handleOutgoing) { | ||
layer.handleOutgoing(queueName, message, next); | ||
} else { | ||
next(null, queueName, message); | ||
} | ||
} else { | ||
layer(queueName, message, next); | ||
} | ||
} | ||
@@ -77,3 +68,3 @@ | ||
Bus.prototype.correlate = require('./middleware/correlate'); | ||
Bus.prototype.log = require('./middleware/log'); | ||
Bus.prototype.logger = require('./middleware/logger'); | ||
Bus.prototype.package = require('./middleware/package'); | ||
@@ -80,0 +71,0 @@ Bus.prototype.retry = require('./middleware/retry'); |
@@ -9,3 +9,3 @@ { | ||
"description": "Simple service bus for sending events between processes using amqp.", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/mateodelnorte/servicebus", | ||
@@ -12,0 +12,0 @@ "repository": { |
@@ -125,5 +125,5 @@ # servicebus | ||
### Log | ||
### Logger | ||
Log ensures that incoming and outgoing messages are logged to stdout via the debug module. | ||
Logger ensures that incoming and outgoing messages are logged to stdout via the debug module. (Use this in non-high throughput scenarios, otherwise you'll have some very quickly growing logs) | ||
@@ -130,0 +130,0 @@ ### Package |
@@ -12,5 +12,5 @@ require('longjohn') | ||
bus.use(bus.correlate()); | ||
bus.use(bus.log()); | ||
bus.use(bus.logger()); | ||
bus.use(bus.retry()); | ||
module.exports.bus = bus; |
34137
770