-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates basic client with
sendMessage
- Loading branch information
Rick Harrison
committed
Jul 19, 2016
0 parents
commit 63ec7f4
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
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; |
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
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" | ||
} | ||
} |