Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/panthershark/aws-sqs-stream
AWS SQS library written using node.js streams.
https://github.com/panthershark/aws-sqs-stream
Last synced: about 2 months ago
JSON representation
AWS SQS library written using node.js streams.
- Host: GitHub
- URL: https://github.com/panthershark/aws-sqs-stream
- Owner: panthershark
- License: mit
- Created: 2014-03-06T15:46:29.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-25T19:39:42.000Z (over 10 years ago)
- Last Synced: 2024-10-01T09:39:25.741Z (3 months ago)
- Language: JavaScript
- Size: 218 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
aws-sqs-stream
==============AWS SQS library written using node.js streams.
# Usage: Library
```javascript
var SqsStream = require('aws-sqs-stream').SqsStream;
var MemoryStream = require('memory-stream');
var AWS = require('aws-sdk');var sqsOptions = {
"awsConfig": {
"accessKeyId": "STRING",
"secretAccessKey": "STRING",
"region": "us-east-1"
},
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/#######/STRING",
"QueueOptions": {
"MaxNumberOfMessages": 10,
"WaitTimeSeconds": 4,
"VisibilityTimeout": 15
}
};var readStream = new SqsStream(sqsOptions)
var writeStream = new MemoryStream({ objectMode: true });
var sqsClient = new AWS.SQS(sqsOptions.awsConfig);readStream.on('message', function(msg) {
sqsClient.deleteMessage({
QueueUrl: sqsOptions.QueueUrl,
ReceiptHandle: msg.ReceiptHandle
}, function() {
console.log('msg ack');
});});
writeStream.on('finish', function() {
console.log(writeStream.get());
});readStream.pipe(writeStream);
```# Usage: Broadway/Mixdown plugin
```javascript
var broadway = require('broadway');
var MemoryStream = require('memory-stream');
var SqsPlugin = require('aws-sqs-stream').SqsPlugin;
var sqsOptions = {
"awsConfig": {
"accessKeyId": "STRING",
"secretAccessKey": "STRING",
"region": "us-east-1"
},
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/#######/STRING",
"QueueOptions": {
"MaxNumberOfMessages": 10,
"WaitTimeSeconds": 4,
"VisibilityTimeout": 15
}
};var app = {
plugins: new broadway.App()
};// attach the broadway/mixdown plugin
app.plugins.use(new SqsPlugin('sqs'), sqsOptions);// call init to setup the sqsClient
app.plugins.init(function(err) {
var readStream = app.plugins.sqs.messageStream();
var writeStream = new MemoryStream({ objectMode: true });readStream.on('message', function(msg) {
app.plugins.sqs.ack(msg, function() { console.log('msg ack'); });
});writeStream.on('finish', function() {
console.log(writeStream.get());
});readStream.pipe(writeStream);
});```