A simple wrapper on top of message queues.
import { MessageQueue } from '@rfcx/message-queue'
const options = {
...
}
const messageQueue = new MessageQueue('sqs', options)
messageQueue.publish('publication-queue', { foo: 'bar' })
messageQueue.subscribe('subscription-queue', (message: unknown) => {
return true
})
import { MessageQueue } from '@rfcx/message-queue'
const options = {
...
}
const messageQueue = new MessageQueue('sns', options)
messageQueue.publish('publication-topic', { foo: 'bar' })
Creates a new MessageQueue client.
type
- String - client type (sqs
orsns
)options
- Object - additional optionsoptions.topicPrefix
- String - SQS queue or SNS topic prefix (e.g.staging
instaging-event-created
)options.topicPostfix
- String - SQS queue or SNS topic postfix (e.g.staging
inevent-created-staging
)
For SQS
client: AWS_ACCESS_KEY_ID
, AWS_SECRET_KEY
, AWS_REGION_ID
For SNS
client: AWS_ACCESS_KEY_ID
, AWS_SECRET_KEY
, AWS_REGION_ID
, AWS_ACCOUNT_ID
MESSAGE_QUEUE_ENDPOINT
if you want to use custom endpoint
- Note that
SNS
client does not havesubscribe
method as you can't subscribe directly toSNS
topic.
Publishing to NPM registry is done automatically via GitHub Actions once new release is published in the GitHub repository.
You must have NPM_PUBLISH_TOKEN
secret to be defined in your repository or organization. Reference this or this for instructions.