Version: v0.0.7
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.
List of Available Drivers
Driver | Constant |
---|---|
Sync (Runs your code syncronously) | sync |
AWS SQS | sqs |
Static Import
To import the module statically, you can do
import { Module } from '@nestjs/common';
import { QueueModule } from '@squareboat/nest-queue';
@Module({
imports: [
QueueModule.register({
isGlobal: true,
default: 'sqs',
connections: {
notifications: {
driver: 'sqs',
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';
export default registerAs('queue', () => {
return {
default: 'sqs',
connections: {
notifications: {
driver: 'sqs',
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
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 {}