Permalink
Browse files

Merge pull request #144 from ZeissS/fix-empty-messages

Fixes handling of empty messages
  • Loading branch information...
2 parents 96d09e5 + 4b7f5ae commit 702acb543bdc4125600a8d2e3df8469a7ef759c3 @postwait committed Mar 1, 2013
Showing with 30 additions and 0 deletions.
  1. +4 −0 amqp.js
  2. +26 −0 test/test-receive-empty-messages.js
View
@@ -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) {
@@ -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.