# aws-messaging

> AWS messaging wrapper for multicasting published messages to consumer groups

Latest version **0.1.2** (published 2017-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install aws-messaging
pnpm add aws-messaging
yarn add aws-messaging
bun add aws-messaging
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-05-30 |
| First published | 2017-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | TheConnMan |
| Maintainers | theconnman |
| Keywords | AWS, SNS, SQS, messaging |

## Links

- npm: https://www.npmjs.com/package/aws-messaging
- Repository: https://github.com/TheConnMan/aws-messaging
- Homepage: https://github.com/TheConnMan/aws-messaging#readme
- Issues: https://github.com/TheConnMan/aws-messaging/issues
- npm.io page: https://npm.io/package/aws-messaging

## Dependencies (1)

- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.58.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2017-05-30
- 0.1.1 — 2017-05-30
- 0.1.0 — 2017-05-30

## README

# AWS Messaging

[![NPM](https://nodei.co/npm/aws-messaging.png)](https://nodei.co/npm/aws-messaging/)

AWS messaging wrapper for multicasting published messages to consumer groups

## Description

For low throughput messaging queues (e.g. domain object persistence topics, export notifications) Kinesis or Kafka aren't economical. Publishing messages to SNS and multicasting to different SQS queues (one for each consumer cluster) yields the same result of published messages being sent to multiple application clusters.

This library abstracts away the SNS sending and SQS polling instead providing a Publisher class and a Consumer class. A good article describing this technique is <http://docs.aws.amazon.com/sns/latest/dg/SendMessageToSQS.html>.

## Usage

**NOTE:** This library uses default AWS credentials through the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.

```javascript
// TypeScript
import { Consumer, Publisher } from 'aws-messaging';

// JavaScript
var Consumer = require('aws-messaging').Consumer;
var Publisher = require('aws-messaging').Publisher;
```

### Publishing to SNS Topics

First create an [AWS SNS topic](https://console.aws.amazon.com/sns/v2/home) and pull it's SNS topic ARN. Create a `Publisher` and register a JavaScript object class with that topic (or skip this step and send objects directly to that topic as shown further down):

```javascript
var publisher = new Publisher(/* awsRegion (default: us-east-1) */);
publisher.register('arn:aws:sns:us-east-1:000000000000:sns-topic', 'MyClass');

// Publishing with a registered class
var myClass = new MyClass();
publisher.send(myClass);

// Publishing directly to a topic
publisher.sendToTopic(myClass, topic);
```

### Consuming from SQS Topics

First create an [AWS SQS topic](https://console.aws.amazon.com/sqs/home), subscribe it to your SNS topic, and give the SNS topic publish permissions to the SQS topic (details can be found in <http://docs.aws.amazon.com/sns/latest/dg/SendMessageToSQS.html>). **NOTE:** Make sure to set the SQS **Receive Message Wait Time** to 20s for long polling and to reduce the total number of SQS API calls (which you are billed for).

```javascript
var consumer = new Consumer('https://sqs.us-east-1.amazonaws.com/000000000000/sqs-topic', /* awsRegion (default: us-east-1) */, item => {
  // Perform work with the item
  return Promise.resolve();
});

// Start the consumer function
consumer.start();

// Optionally stop SQS consumption
consumer.stop();
```

---
_Source: https://npm.io/package/aws-messaging · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
