Last active
November 11, 2021 16:42
-
-
Save bmorrisondev/7b68d20ed6370fbdf33f17f373dfb7d9 to your computer and use it in GitHub Desktop.
A simple SQS setup in JavaScript
This file contains 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
// 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(); |
This file contains 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
// 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