Version: Next

Configuration

Just like any other nestjs packages, we need to import the Mailman module in your application. The package support both static and dynamic imports for the module. To learn the difference between the two, check here.

Note

Since, you may want to dispatch jobs from several modules, hence the QueueModule is imported globally.

Static Import

To import the module statically, you can do

import { Module } from '@nestjs/common';
import { QueueModule } from '@squareboat/nest-queue';
import { SqsQueueDriver } from '@squareboat/nest-queue-sqs';
@Module({
imports: [
QueueModule.register({
isGlobal: true,
default: 'notifications',
connections: {
notifications: {
driver: SqsQueueDriver, // you can use any available driver here
apiVersion: '2012-11-05',
profile: 'default',
prefix: 'https://sqs.us-east-1.amazonaws.com/123456789012',
queue: 'MyQueue',
suffix: '',
region: 'us-east-1',
},
},
}),
],
})
export class AppModule {}

Dynamic Import (recommended)

To import the module dynamically, you can do

config/queue.ts
import { registerAs } from '@nestjs/config';
import { QueueOptions } from '@squareboat/nest-queue';
import { SqsQueueDriver } from '@squareboat/nest-queue-sqs';
export default registerAs('queue', () => {
return {
default: 'notifications',
connections: {
notifications: {
driver: SqsQueueDriver, // you can use any available driver here
apiVersion: '2012-11-05',
profile: process.env.AWS_PROFILE,
prefix: process.env.AWS_SQS_PREFIX,
queue: process.env.AWS_SQS_QUEUE,
suffix: '',
region: process.env.AWS_REGION,
},
},
} as QueueOptions;
});
info

AWS_PROFILE, AWS_SQS_PREFIX, AWS_SQS_QUEUE, AWS_REGION are environment variables and live in .env(.local or .production) file.

Note that these attributes will change as per the driver.

note

Remember to load the configuration in ConfigModule. Read more about it here.

Now that the configuration is loaded, you can import your module asynchronously.

import { Module } from '@nestjs/common';
import { QueueModule } from '@squareboat/nest-queue';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
QueueModule.registerAsync({
isGlobal: true,
imports: [ConfigModule],
useFactory: (config: ConfigService) => config.get('queue'),
inject: [ConfigService],
}),
],
})
export class AppModule {}

List of Available Drivers

DriverConstant
Sync (Runs your code syncronously)SyncQueueDriver
AWS SQSSqsQueueDriver
RedisRedisQueueDriver

To learn more about various drivers, head over to the drivers section.