Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 73e1eb8

Browse files
authored
Merge pull request #2 from aspecto-io/fix/docs
Fix main reference, update docs
2 parents 7de41bc + d05ed7a commit 73e1eb8

File tree

8 files changed

+48
-78
lines changed

8 files changed

+48
-78
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build PR
1+
name: Build
22
on: [push]
33

44
jobs:

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
/node_modules
44
/.github
55
/scripts
6+
.prettierrc
7+
docker-compose.yml
8+
.editorconfig

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44

55
SQS/SNS producer/consumer library. Provides an ability to pass payloads though s3.
66

7+
## Motivation
8+
9+
[Aspecto](https://www.aspecto.io/?utm_source=github&utm_medium=sqs-sns-big-payload&utm_campaign=readme-p1&utm_content=v1) helps modern development teams solve production issues before they evolve. We collect real production data and perform deep API analysis over it to autogenerate tests and monitor services stability. As a result, we often need to handle large payloads which can't be used with SQS & SNS due to the hard size limit. This library was developed to overcome this challenge - it enables you to manage Amazon SNS & SQS message payloads with Amazon S3 when dealing with payloads larger than 256KB. Key functionality includes:
10+
11+
- Controlling whether message payloads are always stored in Amazon S3 or only when a message's size exceeds 256KB.
12+
- Send a message that references a single message object stored in an Amazon S3 bucket.
13+
- Get the corresponding message object from an Amazon S3 bucket.
14+
- Handle the interface for large messages between SNS to SQS via S3 bucket in the middle
15+
716
## Instalation
817

918
```
1019
npm install sns-sqs-big-payload
1120
```
1221

22+
Important:
23+
24+
> Make sure you also have `aws-sdk` installed, bacause it's listed as a peer dependency, so won't be installed automatically.
25+
1326
## Usage
1427

1528
The library exports 3 clients:
@@ -18,8 +31,7 @@ The library exports 3 clients:
1831
- SQS producer
1932
- SQS consumer
2033

21-
The reason they belong to the same repository and npm package
22-
is that ther're is kind of a contract that they all share when sending the payload though S3.
34+
All 3 clients are under the same repository since they share a similar contract when sending payloads via S3.
2335

2436
### SNS Producer
2537

@@ -162,10 +174,16 @@ You may subscribe to those events to add logging for example.
162174

163175
## Testing
164176

165-
Since this library relies heavily on AWS API there's not much sense to test it in isolation by using mocks.
166-
So in order to run test you either need to have local stack or use a real sqs queues and sns topics.
177+
Since this library heavily relies on AWS APIs, it is less relevant to run an isolated test using mocks. As a result, we recommend testing it using a [localstack](https://github.com/localstack/localstack) or by using real SQS queues and SNS topics.
167178

168179
To run localstack on mac:
180+
169181
```sh
170182
TMPDIR=/private$TMPDIR docker-compose up
171183
```
184+
185+
To run unit tests:
186+
187+
```sh
188+
npm test
189+
```

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
{
22
"name": "sns-sqs-big-payload",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"license": "MIT",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
57
"scripts": {
68
"test": "jest",
79
"build": "npm run clean && tsc",
810
"clean": "rm -rf ./dist/*"
911
},
1012
"dependencies": {
11-
"aws-sdk": "^2.644.0",
1213
"uuid": "^7.0.2"
1314
},
1415
"devDependencies": {
1516
"@types/jest": "^25.1.4",
1617
"@types/node": "^13.9.2",
18+
"aws-sdk": "^2.644.0",
1719
"jest": "^25.1.0",
1820
"ts-jest": "^25.2.1",
19-
"typescript": "^3.8.3",
20-
"wait-on": "^4.0.1"
21+
"typescript": "^3.8.3"
2122
},
2223
"repository": {
2324
"type": "git",
@@ -28,8 +29,6 @@
2829
},
2930
"homepage": "https://github.com/aspecto-io/sns-sqs-big-payload",
3031
"prepublish": "tsc",
31-
"main": "./build/index.js",
32-
"types": "./build/index.d.ts",
3332
"jest": {
3433
"preset": "ts-jest",
3534
"testMatch": [
@@ -58,5 +57,8 @@
5857
"large",
5958
"big",
6059
"payload"
61-
]
60+
],
61+
"peerDependencies": {
62+
"aws-sdk": "^2.644.0"
63+
}
6264
}

src/sns-producer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export class SnsProducer {
4141
});
4242
}
4343
if (options.allPayloadThoughS3 || options.largePayloadThoughS3) {
44+
if (!options.s3Bucket) {
45+
throw new Error(
46+
'Need to specify "s3Bucket" option when using allPayloadThoughS3 or largePayloadThoughS3.'
47+
);
48+
}
49+
4450
if (options.s3) {
4551
this.s3 = options.s3;
4652
} else {

src/sqs-consumer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class SqsConsumer {
130130
}
131131

132132
private async handleSqsResponse(result: ReceiveMessageResult): Promise<void> {
133-
if (result) {
133+
if (result && result.Messages) {
134134
await Promise.all(result.Messages.map((message) => this.processMessage(message)));
135135
}
136136
}

src/sqs-producer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export class SqsProducer {
4141
});
4242
}
4343
if (options.largePayloadThoughS3 || options.allPayloadThoughS3) {
44+
if (!options.s3Bucket) {
45+
throw new Error(
46+
'Need to specify "s3Bucket" option when using allPayloadThoughS3 or largePayloadThoughS3.'
47+
);
48+
}
4449
if (options.s3) {
4550
this.s3 = options.s3;
4651
} else {

yarn.lock

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -151,46 +151,6 @@
151151
exec-sh "^0.3.2"
152152
minimist "^1.2.0"
153153

154-
"@hapi/address@^4.0.1":
155-
version "4.0.1"
156-
resolved "https://registry.yarnpkg.com/@hapi/address/-/address-4.0.1.tgz#267301ddf7bc453718377a6fb3832a2f04a721dd"
157-
integrity sha512-0oEP5UiyV4f3d6cBL8F3Z5S7iWSX39Knnl0lY8i+6gfmmIBj44JCBNtcMgwyS+5v7j3VYavNay0NFHDS+UGQcw==
158-
dependencies:
159-
"@hapi/hoek" "^9.0.0"
160-
161-
"@hapi/formula@^2.0.0":
162-
version "2.0.0"
163-
resolved "https://registry.yarnpkg.com/@hapi/formula/-/formula-2.0.0.tgz#edade0619ed58c8e4f164f233cda70211e787128"
164-
integrity sha512-V87P8fv7PI0LH7LiVi8Lkf3x+KCO7pQozXRssAHNXXL9L1K+uyu4XypLXwxqVDKgyQai6qj3/KteNlrqDx4W5A==
165-
166-
"@hapi/hoek@^9.0.0":
167-
version "9.0.4"
168-
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.0.4.tgz#e80ad4e8e8d2adc6c77d985f698447e8628b6010"
169-
integrity sha512-EwaJS7RjoXUZ2cXXKZZxZqieGtc7RbvQhUy8FwDoMQtxWVi14tFjeFCYPZAM1mBCpOpiBpyaZbb9NeHc7eGKgw==
170-
171-
"@hapi/joi@^17.1.0":
172-
version "17.1.1"
173-
resolved "https://registry.yarnpkg.com/@hapi/joi/-/joi-17.1.1.tgz#9cc8d7e2c2213d1e46708c6260184b447c661350"
174-
integrity sha512-p4DKeZAoeZW4g3u7ZeRo+vCDuSDgSvtsB/NpfjXEHTUjSeINAi/RrVOWiVQ1isaoLzMvFEhe8n5065mQq1AdQg==
175-
dependencies:
176-
"@hapi/address" "^4.0.1"
177-
"@hapi/formula" "^2.0.0"
178-
"@hapi/hoek" "^9.0.0"
179-
"@hapi/pinpoint" "^2.0.0"
180-
"@hapi/topo" "^5.0.0"
181-
182-
"@hapi/pinpoint@^2.0.0":
183-
version "2.0.0"
184-
resolved "https://registry.yarnpkg.com/@hapi/pinpoint/-/pinpoint-2.0.0.tgz#805b40d4dbec04fc116a73089494e00f073de8df"
185-
integrity sha512-vzXR5MY7n4XeIvLpfl3HtE3coZYO4raKXW766R6DZw/6aLqR26iuZ109K7a0NtF2Db0jxqh7xz2AxkUwpUFybw==
186-
187-
"@hapi/topo@^5.0.0":
188-
version "5.0.0"
189-
resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-5.0.0.tgz#c19af8577fa393a06e9c77b60995af959be721e7"
190-
integrity sha512-tFJlT47db0kMqVm3H4nQYgn6Pwg10GTZHb1pwmSiv1K4ks6drQOtfEF5ZnPjkvC+y4/bUPHK+bc87QvLcL+WMw==
191-
dependencies:
192-
"@hapi/hoek" "^9.0.0"
193-
194154
"@istanbuljs/load-nyc-config@^1.0.0":
195155
version "1.0.0"
196156
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.0.0.tgz#10602de5570baea82f8afbfa2630b24e7a8cfe5b"
@@ -2749,7 +2709,7 @@ [email protected]:
27492709
dependencies:
27502710
lodash "^4.17.15"
27512711

2752-
request-promise-native@^1.0.7, request-promise-native@^1.0.8:
2712+
request-promise-native@^1.0.7:
27532713
version "1.0.8"
27542714
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.8.tgz#a455b960b826e44e2bf8999af64dff2bfe58cb36"
27552715
integrity sha512-dapwLGqkHtwL5AEbfenuzjTYg35Jd6KPytsC2/TLkVMz8rm+tNt72MGUWT1RP/aYawMpN6HqbNGBQaRcBtjQMQ==
@@ -2840,13 +2800,6 @@ rsvp@^4.8.4:
28402800
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
28412801
integrity sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==
28422802

2843-
rxjs@^6.5.4:
2844-
version "6.5.4"
2845-
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.4.tgz#e0777fe0d184cec7872df147f303572d414e211c"
2846-
integrity sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==
2847-
dependencies:
2848-
tslib "^1.9.0"
2849-
28502803
safe-buffer@^5.0.1, safe-buffer@^5.1.2:
28512804
version "5.2.0"
28522805
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
@@ -3282,11 +3235,6 @@ ts-jest@^25.2.1:
32823235
semver "^5.5"
32833236
yargs-parser "^16.1.0"
32843237

3285-
tslib@^1.9.0:
3286-
version "1.11.1"
3287-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
3288-
integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==
3289-
32903238
tunnel-agent@^0.6.0:
32913239
version "0.6.0"
32923240
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
@@ -3430,18 +3378,6 @@ w3c-xmlserializer@^1.1.2:
34303378
webidl-conversions "^4.0.2"
34313379
xml-name-validator "^3.0.0"
34323380

3433-
wait-on@^4.0.1:
3434-
version "4.0.1"
3435-
resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-4.0.1.tgz#c49ca18b1ea60580404feed9df76ab3af2425a56"
3436-
integrity sha512-x83fmTH2X0KL7vXoGt9aV5x4SMCvO8A/NbwWpaYYh4NJ16d3KSgbHwBy9dVdHj0B30cEhOFRvDob4fnpUmZxvA==
3437-
dependencies:
3438-
"@hapi/joi" "^17.1.0"
3439-
lodash "^4.17.15"
3440-
minimist "^1.2.0"
3441-
request "^2.88.0"
3442-
request-promise-native "^1.0.8"
3443-
rxjs "^6.5.4"
3444-
34453381
walker@^1.0.7, walker@~1.0.5:
34463382
version "1.0.7"
34473383
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"

0 commit comments

Comments
 (0)