jeudi 29 janvier 2015

Amazon sqs node.js worker

I've created a node.js worker that processes my jobs stored in the queue, and every time a jobs comes in sqs service I get a POST request to my node.js worker, after that I try to read the messages from the queue, but the only thing I get is :



{"ResponseMetadata":{"RequestId":"9d6121e0-4241-5bc8-a000-6ca41ae431f9"}}


My question is, why can't I get the messages (sqs says that they are in flight), and the second thing is I know I get my message when SQS service makes a POST request, then why is there no RecipientHandle in that request to delete the message?


my worker.js



AWS.config.update({
accessKeyId: AWS_CONFIG.ACCESS_KEY_ID,
secretAccessKey: AWS_CONFIG.SECRET_ACCESS_KEY,
region: AWS_CONFIG.REGION
});

var sqs = new AWS.SQS();

var i = 0;
router.post('/', function(req, res, next){

if (!dataIsSet(req.body)){
req.send(569).end();
return;
}
var msgId = req.header('x-aws-sqsd-msgid'),
name = req.body.name,
message = req.body.data;

console.log('Headers : ');
console.log(JSON.stringify(req.headers));
console.log('============ Request came in ============' + (i++) );
res.status(200).send('Msg');
var data = {};

sqs.receiveMessage({
QueueUrl: AWS_CONFIG.SQS.QUEUE_URL,
MaxNumberOfMessages: 10,
VisibilityTimeout: 20,
WaitTimeSeconds: 0
}, function (err, response) {

console.log('============ Message from queue : ============');
console.log(JSON.stringify(response));
if (err) {
console.log(JSON.stringify(err));
//callback(err);
} else {
console.log(JSON.stringify(response));
data = response;
}
});


});


Thanks!





Aucun commentaire:

Enregistrer un commentaire