【发布时间】:2016-08-06 05:52:30
【问题描述】:
我是 SQS 和 nodejs 的新手。我想在队列不为空时接收消息,但在收到第一条消息后它停止工作。我的代码仅在服务器启动时读取第一条消息。我怎样才能一直阅读消息?
sqs.receiveMessage({
QueueUrl: queueUri,
WaitTimeSeconds: 3,
MaxNumberOfMessages: 1
}, function(err, data) {
// If there are any messages to get
if (data.Messages) {
// Get the first message (should be the only one since we said to only get one above)
var message = data.Messages[0],
body = JSON.parse(message.Body);
var bucketName = body.Records[0].s3.bucket.name;
var fullName = body.Records[0].s3.object.key;
var fileName = Path.basename(fullName);
var folderName = Path.dirname(fullName);
var _45px = {
width: 45,
dstnKey: fileName,
destinationPath: "thumbnails"
};
removeFromQueue(message);
}
});
【问题讨论】:
标签: node.js amazon-web-services amazon-sqs