Permalink
Browse files

# delete/clear queue messages

  • Loading branch information...
1 parent 2e82aa1 commit a36ce6eff6a794771ad532395642d47427e700dc Juan Pablo Garcia Dalolla committed Sep 18, 2011
Showing with 56 additions and 1 deletion.
  1. +24 −1 lib/waz-queues/service.js
  2. +32 −0 test/waz-queues/service.test.js
View
25 lib/waz-queues/service.js
@@ -86,7 +86,8 @@ Service.prototype.putMessage = function(name, message, options, callback){
});
};
-Service.prototype.getMessages = function(name, options, callback){
+// It can be used to peek messages by providing the options peekonly=true and [numofmessages=32max]
+Service.prototype.getMessages = function(name, options, callback) {
var service = this;
service.execute('get', name + '/messages', options, {'x-ms-version': '2009-09-19'}, null, function(response) {
@@ -105,4 +106,26 @@ Service.prototype.getMessages = function(name, options, callback){
// Non-whitespace before first tag.\nLine: 0\nColumn: 1\nChar
}).parseString(response.body);
});
+};
+
+Service.prototype.deleteMessage = function(name, messageId, popreceipt, callback){
+ var service = this;
+
+ service.execute('delete', name + '/messages/' + messageId, {popreceipt: popreceipt}, {'x-ms-version': '2009-09-19'}, null, function(response) {
+ if (service.parseError(response, callback))
+ return;
+
+ callback(null, response.headers);
+ });
+};
+
+Service.prototype.clearMessages = function(name, callback){
+ var service = this;
+
+ service.execute('delete', name + '/messages', null, {'x-ms-version': '2009-09-19'}, null, function(response) {
+ if (service.parseError(response, callback))
+ return;
+
+ callback(null, response.headers);
+ });
};
View
32 test/waz-queues/service.test.js
@@ -354,4 +354,36 @@ module.exports = {
mock.verify();
},
+
+ 'should delete a message from a queue': function(){
+ var service = new Service({});
+ var mock = sinon.mock(service);
+
+ mock.expects("execute").withArgs('delete', 'queue1/messages/messageid', { popreceipt: 'popreceipt-value' }, { 'x-ms-version': '2009-09-19' }, null)
+ .yields({statusCode: 204, headers: { 'x-ms-version': '2009-09-19', 'x-ms-request-id': 'id'}})
+ .once();
+
+ service.deleteMessage('queue1', 'messageid', 'popreceipt-value',function(err, data){
+ assert.equal(err, null);
+ assert.equal(data['x-ms-request-id'], 'id');
+ });
+
+ mock.verify();
+ },
+
+ 'should delete all messages from a queue': function(){
+ var service = new Service({});
+ var mock = sinon.mock(service);
+
+ mock.expects("execute").withArgs('delete', 'queue1/messages', null, { 'x-ms-version': '2009-09-19' }, null)
+ .yields({statusCode: 204, headers: { 'x-ms-version': '2009-09-19', 'x-ms-request-id': 'id'}})
+ .once();
+
+ service.clearMessages('queue1',function(err, data){
+ assert.equal(err, null);
+ assert.equal(data['x-ms-request-id'], 'id');
+ });
+
+ mock.verify();
+ },
}

0 comments on commit a36ce6e

Please sign in to comment.