diff --git a/lib/stomp.js b/lib/stomp.js index bb51546..cd65f21 100644 --- a/lib/stomp.js +++ b/lib/stomp.js @@ -51,7 +51,6 @@ function parse_headers(raw_headers) { headers[header_key] = header_val; continue; } - headers[header[0].trim()] = header[1].trim(); } return headers; }; @@ -137,6 +136,8 @@ function _setupListeners(stomp) { var socket = stomp.socket; + socket.setKeepAlive(true); + socket.on('drain', function(data) { log.debug('draining'); }); @@ -284,7 +285,8 @@ Stomp.prototype.connect = function() { // Takes a `Frame` object // Stomp.prototype.is_a_message = function(this_frame) { - return (this_frame.headers !== null && utils.really_defined(this_frame.headers['message-id'])) + return (this_frame.headers !== null && + utils.really_defined(this_frame.headers['message-id'])) } // ## Stomp.should_run_message_callback @@ -294,9 +296,13 @@ Stomp.prototype.is_a_message = function(this_frame) { // Takes a `Frame` object // Stomp.prototype.should_run_message_callback = function(this_frame) { - var subscription = this._subscribed_to[this_frame.headers.destination]; + // The matching subscribed queue will be found in the subscription headers + // in the case of a reply-to temp queue with rabbitmq + var subscription = this._subscribed_to[this_frame.headers.destination] || + this._subscribed_to[this_frame.headers.subscription]; if (this_frame.headers.destination !== null && subscription !== null) { - if (subscription.enabled && subscription.callback !== null && typeof(subscription.callback) == 'function') { + if (subscription.enabled && subscription.callback !== null && + typeof subscription.callback === 'function') { subscription.callback(this_frame.body, this_frame.headers); } } @@ -399,6 +405,31 @@ Stomp.prototype.ack = function(message_id) { this.log.debug('acknowledged message: ' + message_id); }; + +// +// ## Stomp.nack(message_id) +// +// **Deny received message** +// +// Takes a string representing the message id to nack +// +Stomp.prototype.nack = function(message_id) { + send_command(this, 'NACK', {'message-id': message_id}); + this.log.debug('denied message: ' + message_id); +}; + +// +// ## Stomp.nack(message_id) +// +// **Deny received message** +// +// Takes a string representing the message id to nack +// +Stomp.prototype.nack = function(message_id) { + send_command(this, 'NACK', {'message-id': message_id}); + this.log.debug('denied message: ' + message_id); +}; + // // ## Stomp.begin() //