This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { AppController } from './app.controller'; | |
import { AppService } from './app.service'; | |
import { QueueConfigModule } from './config/queue/config.module'; | |
import { PurchaseModule } from './purchase/purchase.module'; | |
@Module({ | |
imports: [QueueConfigModule, PurchaseModule], | |
controllers: [AppController], | |
providers: [AppService], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BullModule } from '@nestjs/bull'; | |
import { Module } from '@nestjs/common'; | |
import { PurchaseProcessor } from './purchase-queue.processor'; | |
@Module({ | |
imports: [ | |
BullModule.registerQueue({ | |
name: 'send-invoice', | |
}), | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { OnQueueCompleted, Process, Processor } from '@nestjs/bull'; | |
import { Logger } from '@nestjs/common'; | |
import { Job } from 'bull'; | |
@Processor('send-invoice') | |
export class PurchaseProcessor { | |
private readonly logger = new Logger(PurchaseProcessor.name); | |
// Consumers | |
@Process() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BullModule } from '@nestjs/bull'; | |
import { Module } from '@nestjs/common'; | |
import { PurchaseQueueModule } from 'src/job/purchase/purchase-queue.module'; | |
import { PurchaseController } from './purchase.controller'; | |
import { PurchaseService } from './purchase.service'; | |
@Module({ | |
imports: [PurchaseQueueModule], | |
controllers: [PurchaseController], | |
providers: [PurchaseService], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { InjectQueue } from '@nestjs/bull'; | |
import { Injectable } from '@nestjs/common'; | |
import { Queue } from 'bull'; | |
import { IUserPurchase } from './interface/user-purchasing.interface'; | |
@Injectable() | |
export class PurchaseService { | |
constructor(@InjectQueue('send-invoice') private purchaseQueue: Queue) {} | |
async sendInvoiceToCustomer(data: IUserPurchase[]) { | |
// Producers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, Post } from '@nestjs/common'; | |
import { IUserPurchase } from './interface/user-purchasing.interface'; | |
import { PurchaseService } from './purchase.service'; | |
@Controller('/api/purchase') | |
export class PurchaseController { | |
constructor(private readonly purchaseService: PurchaseService) {} | |
@Post() | |
async send() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as dotenv from 'dotenv'; | |
import * as fs from 'fs'; | |
const env = dotenv.parse(fs.readFileSync('.env')); | |
export default { | |
redis: { | |
host: env.REDIS_HOST, | |
port: env.REDIS_PORT, | |
db: env.REDIS_DB, | |
password: env.REDIS_PASSWORD, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SharedBullConfigurationFactory } from '@nestjs/bull'; | |
import { Injectable } from '@nestjs/common'; | |
import { QueueOptions } from 'bull'; | |
import * as config from './config'; | |
@Injectable() | |
export class QueueConfigProvider implements SharedBullConfigurationFactory { | |
createSharedConfiguration(): QueueOptions { | |
return config as any; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BullModule } from '@nestjs/bull'; | |
import { Module } from '@nestjs/common'; | |
import { PurchaseQueueModule } from 'src/job/purchase/purchase-queue.module'; | |
import { PurchaseProcessor } from 'src/job/purchase/purchase-queue.processor'; | |
import { QueueConfigProvider } from './config.provider'; | |
@Module({ | |
imports: [ | |
BullModule.forRootAsync({ useClass: QueueConfigProvider }), | |
BullModule.registerQueue({ name: 'send-invoice' }), |