https://github.com/fgiova/fastify-sqs-sns-publisher
This plugin for fastify 4.x allows you to publish messages to AWS SQS queues and SNS topics, using a simple interface.
https://github.com/fgiova/fastify-sqs-sns-publisher
fastify fastify-plugin sns sqs
Last synced: 3 months ago
JSON representation
This plugin for fastify 4.x allows you to publish messages to AWS SQS queues and SNS topics, using a simple interface.
- Host: GitHub
- URL: https://github.com/fgiova/fastify-sqs-sns-publisher
- Owner: fgiova
- License: mit
- Created: 2023-08-22T13:20:57.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-05T08:30:31.000Z (over 1 year ago)
- Last Synced: 2025-03-02T01:59:13.902Z (4 months ago)
- Topics: fastify, fastify-plugin, sns, sqs
- Language: TypeScript
- Homepage:
- Size: 187 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify SQS/SNS publisher plugin
[](https://www.npmjs.com/package/@fgiova/fastify-sqs-sns-publisher)

[](http://www.typescriptlang.org/)
[](https://codeclimate.com/github/fgiova/fastify-sqs-sns-publisher/maintainability)
[](https://codeclimate.com/github/fgiova/fastify-sqs-sns-publisher/test_coverage)## Description
This plugin for fastify 4.x allows you to publish messages to AWS SQS queues and SNS topics, using a simple interface.**Warning**
To use this plugin, you must have correctly configured your [AWS credentials](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html).## Install
```bash
npm i @fgiova/fastify-sqs-sns-publisher
```### Usage
```js
const fastify = require("fastify")()
const fastifySqsSnsPublisher = require("@fgiova/fastify-sqs-sns-publisher");
app.register(fastifySqsSnsPublisher, {
sqs: {
region: "eu-central-1",
},
sns: {
region: "eu-central-1",
},
});// publish simple message to SQS
app.messageToSQS({message:"test-sqs"}, "arn:aws:sqs:eu-central-1:000000000000:test-queue");// publish batch message to SQS (not limited to 10 messages)
app.messagesBatchToSQS([{message:"test-sqs-1"}, {message:"test-sqs-2"}], "arn:aws:sqs:eu-central-1:000000000000:test-queue");// publish delayed message to SQS (delay in seconds)
app.delayedMessageToSQS({message:"test-sqs"}, "test-queue", 10);// publish batch delayed message to SQS (delay in seconds and not limited to 10 messages)
app.delayedBatchToSQS([{message:"test-sqs-1"}, {message:"test-sqs-2"}], "arn:aws:sqs:eu-central-1:000000000000:test-queue", 10);// publish simple message to SNS
app.messageToSNS({message:"test-sns"}, "arn:aws:sns:eu-central-1:000000000000:test-topic");// publish batch message to SNS (not limited to 10 messages)
app.messagesBatchToSNS([{message:"test-sns-1"}, {message:"test-sns-2"}], "arn:aws:sns:eu-central-1:000000000000:test-topic");```
You can also send messages with attributes using the message creation class PublisherMessage:
```js
const fastify = require("fastify")()
const fastifySqsSnsPublisher = require("@fgiova/fastify-sqs-sns-publisher");
const {PublisherMessage} = require("@fgiova/fastify-sqs-sns-publisher");
app.register(fastifySqsSnsPublisher, {
sqs: {
region: "eu-central-1",
},
sns: {
region: "eu-central-1",
},
});// publish simple message to SQS
app.messageToSQS(new PublisherMessage({message:"test-sqs"}, {attr1: "value1"}), "arn:aws:sqs:eu-central-1:000000000000:test-queue");// publish batch message to SQS (not limited to 10 messages)
app.messagesBatchToSQS([new PublisherMessage({message:"test-sqs-1"}, {attr1: "value1"}), new PublisherMessage({message:"test-sqs-2"}, {attr1: "value1"})], "arn:aws:sqs:eu-central-1:000000000000:test-queue");// publish delayed message to SQS (delay in seconds)
app.messageToSQS(new PublisherMessage({message:"test-sqs"}, {attr1: "value1"}, 10),"arn:aws:sqs:eu-central-1:000000000000:test-queue");// publish batch delayed message to SQS (delay in seconds and not limited to 10 messages)
app.messagesBatchToSQS([new PublisherMessage({message:"test-sqs-1"}, {attr1: "value1"}, 5), new PublisherMessage({message:"test-sqs-2"}, {attr1: "value1"}, 10)], "arn:aws:sqs:eu-central-1:000000000000:test-queue");// publish simple message to SNS
app.messageToSNS(new PublisherMessage({message:"test-sns"}, {attr1: "value1"}), "arn:aws:sns:eu-central-1:000000000000:test-topic");// publish batch message to SNS (not limited to 10 messages)
app.messagesBatchToSNS([new PublisherMessage({message:"test-sns-1"}, {attr1: "value1"}), new PublisherMessage({message:"test-sns-2"}, {attr1: "value1"})], "arn:aws:sns:eu-central-1:000000000000:test-topic");```
The PublisherMessage support the following attributes:
| Attribute type | Message Type |
|----------------|--------------|
| string | SQS or SNS |
| number | SQS or SNS |
| string[] | SNS |### Options
| Option | Type | Description |
|---------------|--------|--------------------------------------------------------------------------------------------|
| sqs | object | SQS configuration |
| sqs.region | string | AWS Region (mandatory) |
| sqs.endpoint | string | The SQS endpoint to use. |
| sns | object | SNS configuration |
| sns.region | string | AWS Region (mandatory) |
| sns.endpoint | string | The SNS endpoint to use. |
| undiciOptions | object | Undici Pool configuration options |
| signer | object | [Signer](https://github.com/fgiova/aws-signature) instance configuration or Signer options |## License
Licensed under [MIT](./LICENSE).### Acknowledgements
This project is kindly sponsored by: isendu Srl [www.isendu.com](https://www.isendu.com)