Skip to content
39 changes: 35 additions & 4 deletions lib/stomp.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function parse_headers(raw_headers) {
headers[header_key] = header_val;
continue;
}
headers[header[0].trim()] = header[1].trim();
}
return headers;
};
Expand Down Expand Up @@ -137,6 +136,8 @@ function _setupListeners(stomp) {

var socket = stomp.socket;

socket.setKeepAlive(true);

socket.on('drain', function(data) {
log.debug('draining');
});
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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()
//
Expand Down