Drivers
In this section, we will see how you can various drivers very easily in the application.
This package supports the following drivers as of now
Driver | Constant |
---|---|
Sync (Runs your code syncronously) | SyncQueueDriver |
AWS SQS | SqsQueueDriver |
Redis | RedisQueueDriver |
Sync Driver
This is the most easiest driver out of all. There can be some cases where you may want to run your code synchronously for some testing or debugging purpose. So, to keep it simple, this package provides out of the box support for running your Jobs
synchronously.
SQS Driver
AWS SQS is one of the most popular choice of using managed queue service. To use the driver, you need to install it first
Before using it, you need to configure it first like below:
SqsQueueDriver
expects following attributes
Attribute | Description |
---|---|
apiVersion | API version to be used by SQS client |
profile | Profile of the credential that will be read by the aws-sqs sdk from ~/.aws/credentials file |
region | Region where the queue exists |
prefix | URL prefix of the queue |
suffix | URL suffix of the queue |
queue | Queue's name |
Redis Driver
You can also use Redis as your queue driver. You can install it like below
Before using it, you need to configure it first like below:
RedisQueueDriver
expects following attributes
Attribute | Description |
---|---|
host | Host of the redis server |
port | Port of the redis server |
database | Database to be used for queue |
queue | Name of the queue |
Custom Driver
If selected drivers does not meet your requirements, you can create your own custom drivers for queues like beanstalkd
, rabbitmq
etc.
You need to install @squareboat/nest-queue-strategy
package first like below
Now, you need to create two classes MyCustomQueueDriver
and MyCustomQueueJob
. Here for understanding purpose we will use AWS AQS in our MyCustom
driver.
info
Messages are always serialized before being pushed to the queue. And are automatically parsed as object when processed by the QueueWorker
.
note
If you feel that the driver can be used by many other developers like us, we highly recommmend to publish it. We will add it in the official documentation ๐