Skip to content

Commit

Permalink
Merge pull request #144 from ZeissS/fix-empty-messages
Browse files Browse the repository at this point in the history
Fixes handling of empty messages
  • Loading branch information
postwait committed Mar 1, 2013
2 parents 96d09e5 + 4b7f5ae commit 702acb5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions amqp.js
Expand Up @@ -2009,6 +2009,10 @@ Queue.prototype._onContentHeader = function (channel, classInfo, weight, propert
this.currentMessage.size = size;

this.emit('rawMessage', this.currentMessage);
if (size === 0) {
// If the message has no body, directly emit 'end'
this.currentMessage.emit('end');
}
};

Queue.prototype._onContent = function (channel, data) {
Expand Down
26 changes: 26 additions & 0 deletions test/test-receive-empty-messages.js
@@ -0,0 +1,26 @@
require('./harness');

var timeout = null;
connection.addListener('ready', function () {
var exc = connection.exchange('node-json-exchange');

connection.queue('node-json-queue', function(q) {
q.bind('node-json-exchange', '*');

q.subscribe(function (json, headers, deliveryInfo) {
clearTimeout(timeout);
connection.end();
}).addCallback(function () {
puts("Publishing one empty message.");
exc.publish('node-json-queue', '');
});
});
});

timeout = setTimeout(function() {
puts("ERROR: Timeout occured!!!!!!!");
connection.end();
assert.ok(1, 2);
}, 5000);


0 comments on commit 702acb5

Please sign in to comment.