forked from amgnet-weeia/aws-sqs-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqscommand.js
33 lines (30 loc) · 941 Bytes
/
sqscommand.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var SqsCommands = function(queue){
this.queue = queue;
this.actions = {};
var _this = this;
this.actions["send"] = function(message, callback){
_this.queue.sendMessage(message, function(err, data){
if(err) { callback(err); return; }
callback(null, {MessageId : data.MessageId,
MD5OfMessageBody : data.MD5OfMessageBody})
});
};
this.actions["recv"] = function(param,callback){
_this.queue.receiveMessage(function(err, data){
if(err) { callback(err); return; }
callback(null, {Body : data.Body,
MD5OfBody : data.MD5OfBody})
});
};
this.actions["help"] = function(param, callback){
callback(null, "Avaliable commands: " + Object.keys(_this.actions).join(", "));
};
}
SqsCommands.prototype.execCommand = function(name, param, callback){
if(this.actions[name]){
this.actions[name](param, callback);
}else {
callback("unknown command: " + name);
}
}
module.exports = SqsCommands;