Skip to content

Instantly share code, notes, and snippets.

@jagij
Created July 12, 2018 11:58
Show Gist options
  • Save jagij/61b319c7624acf8f1a4cc6174b86b340 to your computer and use it in GitHub Desktop.
Save jagij/61b319c7624acf8f1a4cc6174b86b340 to your computer and use it in GitHub Desktop.
Short node program to test whether your fake-sqs supports long-polling
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');
});
});
@jagij
Copy link
Author

jagij commented Jul 12, 2018

Usage: WAIT_TIME_SECONDS=10 SQS_ENDPOINT=http://localhost:4568 SQS_QUEUE_NAME=abc node longpoll.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment