Skip to content

Commit

Permalink
Creates basic client with sendMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Harrison committed Jul 19, 2016
0 parents commit 63ec7f4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
49 changes: 49 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const aws = require('aws-sdk');

const DEFAULT_OPTS = {
region: 'us-standard',
accessKeyId: '',
secretAccessKey: '',
queue: ''
}

const Client = function Client (opts = DEFAULT_OPTS) {
if (!(this instanceof Client)) return new Client(opts);

const { region, accessKeyId, secretAccessKey, queue } = opts;

console.log(opts);

this.sqs = new aws.SQS({
region,
accessKeyId,
secretAccessKey,
params: {
QueueUrl: queue
}
});
};

/*
* Send a message to the SQS queue
*
* @param payload - An object containing the message data
*/

Client.prototype.sendMessage = function sendMessage(payload) {
return new Promise((resolve, reject) => {
this.sqs.sendMessage({
MessageBody: JSON.stringify(payload)
}, function (err, data) {
if (err) {
return reject(err);
}

resolve(data);
});
});
};

module.exports = Client;
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@meadow/sqs",
"version": "1.0.0",
"description": "Client for Amazon SQS with built-in long polling.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/meadow/sqs.git"
},
"keywords": [
"amazon",
"aws",
"sqs",
"queue",
"message",
"meadow"
],
"authors": [
"Rick Harrison <[email protected]> (https://github.com/rickharrison)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/meadow/sqs/issues"
},
"homepage": "https://github.com/meadow/sqs",
"dependencies": {
"aws-sdk": "^2.4.7"
}
}

0 comments on commit 63ec7f4

Please sign in to comment.