|
| 1 | +[](https://opensource.org/licenses/MIT) [](https://tech.shutterstock.com/kinesis-helpers/) [](https://github.com/shutterstock/kinesis-helpers/actions/workflows/ci.yml) [](https://github.com/shutterstock/kinesis-helpers/actions/workflows/publish.yml) [](https://github.com/shutterstock/kinesis-helpers/actions/workflows/docs.yml) |
| 2 | + |
| 3 | +# Overview |
| 4 | + |
| 5 | +Helper classes for the AWS v3 SDK for JS Kinesis Client (`@aws-sdk/client-kinesis`). |
| 6 | + |
| 7 | +`KinesisRetrier` will retry failed records with a "successful" `PutRecordsCommand` that has items marked as failed within the response, which then need to be retried. |
| 8 | + |
| 9 | +`KinesisBackgroundWriter` will accept writes immediately if there is a concurrent writer slot available, and will block the caller until a slot becomes available if all slots are in use. |
| 10 | + |
| 11 | +# Getting Started |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +The package is available on npm as [@shutterstock/kinesis-helpers](https://www.npmjs.com/package/@shutterstock/kinesis-helpers) |
| 16 | + |
| 17 | +`npm i @shutterstock/kinesis-helpers` |
| 18 | + |
| 19 | +## Importing |
| 20 | + |
| 21 | +```typescript |
| 22 | +import { KinesisBackgroundWriter, KinesisRetrier } from '@shutterstock/kinesis-helpers'; |
| 23 | +``` |
| 24 | + |
| 25 | +## API Documentation |
| 26 | + |
| 27 | +After installing the package, you might want to look at our [API Documentation](https://tech.shutterstock.com/kinesis-helpers/) to learn about all the features available. |
| 28 | + |
| 29 | +# Features |
| 30 | + |
| 31 | +- [KinesisRetrier](https://tech.shutterstock.com/kinesis-helpers/classes/KinesisRetrier.html) |
| 32 | + - Kinesis batch put retrier |
| 33 | + - Batch puts return a list of items that were throttled |
| 34 | + - The batch is marked as succeeded (200 status code) even though items failed |
| 35 | + - As a result, the built-in AWS SDK retry logic will not retry the items in the batch that were throttle |
| 36 | +- [KinesisBackgroundWriter](https://tech.shutterstock.com/kinesis-helpers/classes/KinesisBackgroundWriter.html) |
| 37 | + - Accepts writes immediately if there is a concurrent writer slot available |
| 38 | + - Blocks the caller until a slot becomes available if all slots are in use |
| 39 | + - Collects and exposes errors so the caller can detect if errors have been happening |
| 40 | + |
| 41 | +# Contributing |
| 42 | + |
| 43 | +## Setting up Build Environment |
| 44 | + |
| 45 | +- `nvm use` |
| 46 | +- `npm i` |
| 47 | +- `npm run build` |
| 48 | +- `npm run lint` |
| 49 | +- `npm run test` |
| 50 | + |
| 51 | +## Running Examples |
| 52 | + |
| 53 | +### kinesis-retrier |
| 54 | + |
| 55 | +1. Create Kinesis Data Stream using AWS Console or any other method |
| 56 | + 1. Default name is `kinesis-helpers-test-stream` |
| 57 | + 2. 1 shard is sufficient |
| 58 | + 3. 1 day retention is sufficient |
| 59 | + 4. No encryption is sufficient |
| 60 | + 5. On-demand throughput is sufficient |
| 61 | +2. `npm run example:kinesis-retrier` |
| 62 | + 1. If the stream name was changed: `KINESIS_STREAM_NAME=my-stream-name npm run example:kinesis-retrier` |
| 63 | + |
| 64 | +### kinesis-background-writer |
| 65 | + |
| 66 | +1. Create Kinesis Data Stream using AWS Console or any other method |
| 67 | + 1. Default name is `kinesis-helpers-test-stream` |
| 68 | + 2. 1 shard is sufficient |
| 69 | + 3. 1 day retention is sufficient |
| 70 | + 4. No encryption is sufficient |
| 71 | + 5. On-demand throughput is sufficient |
| 72 | +2. `npm run example:kinesis-background-writer` |
| 73 | + 1. If the stream name was changed: `KINESIS_STREAM_NAME=my-stream-name npm run example:kinesis-background-writer` |
0 commit comments