Skip to content

Instantly share code, notes, and snippets.

@bmorrisondev
Last active November 11, 2021 16:42
Show Gist options
  • Save bmorrisondev/7b68d20ed6370fbdf33f17f373dfb7d9 to your computer and use it in GitHub Desktop.
Save bmorrisondev/7b68d20ed6370fbdf33f17f373dfb7d9 to your computer and use it in GitHub Desktop.
A simple SQS setup in JavaScript
// npm install sqs-consumer
const { Consumer } = require('sqs-consumer')
const app = Consumer.create({
queueUrl: "SQS_URL",
handleMessage: async (message) => {
// Do stuff
}
});
app.on('error', (err) => {
console.error(err);
// logger.error(err);
});
app.on('processing_error', (err) => {
console.error(err);
// logger.error(err);
});
console.log("Starting listener")
app.start();
// npm install sqs-producer
const Producer = require('sqs-producer')
async function sendSqsMessage(message) {
const producer = Producer.create({
queueUrl: "SQS_URL"
})
let sqsMessage = {
id: 'some-id',
body: message
}
return new Promise((resolve, reject) => {
producer.send([sqsMessage], function(err) {
if (err) {
reject(err)
} else {
resolve();
}
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment