【问题标题】:SQS receiveMessage stops to work after first messageSQS receiveMessage 在第一条消息后停止工作
【发布时间】: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


    【解决方案1】:

    该代码将读取一条消息并停止。如果你想继续阅读消息,你需要执行某种循环来继续调用sqs.receiveMessage()。当然这可能很困难,因为它是一个异步调用。我会调查Async library

    【讨论】:

      猜你喜欢
      • 2013-10-09
      • 2015-10-10
      • 1970-01-01
      • 2016-07-21
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多