9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS SQS + Node.jsサンプル

Posted at

キューからメッセージを取り出すサンプル

AWS = require "aws-sdk"
AWS.config.loadFromPath "aws.json"

sqs = new AWS.SQS().client

queueUrl = "ここにキューのURL"

options =
  QueueUrl: queueUrl
  MaxNumberOfMessages: 10
  VisibilityTimeout: 60
  WaitTimeSeconds: 20

sqs.receiveMessage options, (err, data) =>

  console.log "### ERROR!", err if err

  if data?.Messages?.length > 0
    for message, i in data.Messages
      console.log "### メッセージ:#{i}: ###"
      console.log "Body:", message.Body

      params =
        QueueUrl: queueUrl
        ReceiptHandle: message.ReceiptHandle

      sqs.deleteMessage params, (err, data) =>
        console.log "### メッセージを削除 ###"
        console.log "ERROR!:", err if err

  else
    console.log "### メッセージがありません ###" 
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?