Created
July 12, 2018 11:58
-
-
Save jagij/61b319c7624acf8f1a4cc6174b86b340 to your computer and use it in GitHub Desktop.
Short node program to test whether your fake-sqs supports long-polling
This file contains hidden or 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
const AWS = require('aws-sdk'); | |
const sqsOptions = { | |
endpoint: process.env.SQS_ENDPOINT || 'https://sqs.eu-west-1.amazonaws.com', | |
region: process.env.AWS_REGION || 'eu-west-1', | |
} | |
const sqs = new AWS.SQS(sqsOptions); | |
const queueName = process.env.SQS_QUEUE_NAME || "SQS_QUEUE_NAME"; | |
sqs.createQueue({QueueName: queueName}, function(err, resp) { | |
if (err) { | |
console.log('Could not create queue', err); | |
return; | |
} | |
const params = { | |
QueueUrl: resp.QueueUrl, | |
WaitTimeSeconds: process.env.WAIT_TIME_SECONDS || 2, | |
}; | |
const start = new Date(); | |
sqs.receiveMessage(params, function(err, data) { | |
if (err) { | |
console.log("Receive Error", err); | |
return; | |
} | |
const now = new Date(); | |
console.log("Waiting for message took", now-start, 'ms'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
WAIT_TIME_SECONDS=10 SQS_ENDPOINT=http://localhost:4568 SQS_QUEUE_NAME=abc node longpoll.js