Created
November 13, 2012 19:08
-
-
Save mschmulen/4067726 to your computer and use it in GitHub Desktop.
aws queu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var AWS; | |
var queueName = 'TestQueue110512'; | |
var awsAccountId = Ti.App.Properties.getString('aws-account-id'); | |
function pretty(key, value) { | |
if ((key == 'source') || (key == 'type')) { | |
return undefined; | |
} else { | |
return value; | |
} | |
} | |
function success(method, data, response) | |
{ | |
Ti.API.info(method + " Successful"); | |
Ti.API.info(" data: " + JSON.stringify(data, pretty, 2)); | |
Ti.API.info(" response: " + JSON.stringify(response, pretty, 2)); | |
} | |
function error(method, message, response) | |
{ | |
Ti.API.error(method + " Failed"); | |
Ti.API.error(" message: " + message); | |
Ti.API.error(" response: " + JSON.stringify(response, pretty, 2)); | |
} | |
function init() { | |
AWS = require('ti.aws'); | |
AWS.authorize(Titanium.App.Properties.getString('aws.access_key'), Titanium.App.Properties.getString('aws.secret_key')); | |
createQueue(); | |
} | |
function createQueue(){ | |
AWS.SQS.createQueue({ | |
'QueueName' : queueName, | |
//'Label' : 'Test' | |
}, function(data, response) { | |
success('createQueue', data, response); | |
receiveMessage(); | |
}, function(message,response) { | |
error('createQueue', message, response); | |
}); | |
}; | |
function receiveMessage(){ | |
AWS.SQS.receiveMessage({ | |
'AWSAccountId':awsAccountId, | |
'QueueName': queueName | |
}, function(data, response) { | |
if (data.ReceiveMessageResult == null) { | |
Ti.API.warn("data.ReceiveMessageResult is null"); | |
} else { | |
Ti.API.warn("data.ReceiveMessageResult is NOT null"); | |
} | |
Ti.API.info("Output data.ReceiveMessageResult without formatting"); | |
Ti.API.warn(data.ReceiveMessageResult); | |
Ti.API.info("Output data.ReceiveMessageResult with formatting"); | |
Ti.API.warn("Data: " + data.ReceiveMessageResult); | |
Ti.API.info("Stringify data.ReceiveMessageResult"); | |
Ti.API.warn(JSON.stringify(data.ReceiveMessageResult)); | |
Ti.API.info("Stringify data"); | |
Ti.API.warn(JSON.stringify(data)); | |
success('receiveMessage', data, response); | |
}, function(message,response) { | |
error('receiveMessage', message, response); | |
}); | |
}; | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment