1. Install
npm install aws-message-bus-package
2. Config File
You need to create a config.json file in your root/src project and input some AWS informations, like bellow:
{
"host": "localhost",
"port": 4566,
"region": "eu-west-2",
"account": "000000000000",
"snsArn": "arn:aws:sns",
"sqsArn": "arn:aws:sqs",
"awsHost": "localhost.localstack.cloud",
"tags": [
{ "Key": "team", "Value": "your-team-name" },
{ "Key": "appName", "Value": "your-app-name" }
],
"testMode": false
}
3. Sample Usage
const { Infrastructure } = require('aws-message-bus-package');
async () => await Infrastructure.createQueue('your-queue-name');
async () => await Infrastructure.createTopic('your-topic-name');
async () => await Infrastructure.bindTopic('your-topic-name', 'your-queue-name');
Create a new SQS queue
- Create a new SNS topic, if not exists
- Subscribe a SNS topic in a SQS queue
Send a message to SNS topic to do broadcast
- Content: any kind of type/object, this will be transformed into a JSON format
Send a message to SQS queue direct
- Content: any kind of type/object, this will be transformed into a JSON format
- Params: SQS.Types.SendMessageRequest
- You don't need to inform:
- MessageBody
- MessageAttributes
- QueueUrl
- You don't need to inform:
Send a message to EventBridge informing the SNS topic with the destination. This message will be consumed when it arrives on the scheduled date.
- Content: any kind of type/object, this will be transformed into a JSON format
Handle a consumer to consume queue messages
- Resilience Params:
- maxRetryCount: max number of attempts until send to DLQ
- delaySeconds: the time that will wait between attempts