Skip to content

Commit

Permalink
fix: queue should use only one routing key
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Oct 5, 2023
1 parent 9779e82 commit ba2c8b1
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 85 deletions.
18 changes: 0 additions & 18 deletions docs/using-insomnia-collection.md

This file was deleted.

45 changes: 28 additions & 17 deletions env/.env.sample
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
# This is a sample file generated by sample-env
# app
### Environment File ##################################################################
# This file is a "template" of which env vars need to be defined for your application
########################################################################################

APP_PORT=
APP_PREFIX=
APP_NAME=
NODE_ENV=
API_URL=
CLIENT_URL=
SWAGGER_USER=
ALLOWED_ORIGINS=
ALLOWED_HOSTS=
SWAGGER_PASSWORD=

# database
# database
DB_HOST=
DB_PORT=
DB_USERNAME=
DB_PASSWORD=
DB_DATABASE=

# encryption

# encryption
ENC_IV=
ENC_KEY=

# jwt

# jwt
JWT_ACCESS_EXPIRY=
JWT_REFRESH_EXPIRY=
JWT_SECRET=

# mail

# mail
MAIL_HOST=
MAIL_PASSWORD=
MAIL_USERNAME=
Expand All @@ -36,42 +42,47 @@ MAIL_PREVIEW_EMAIL=
MAIL_SENDER_EMAIL=
MAIL_TEMPLATE_DIR=

# cloudinary

# cloudinary
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=

# redis
# redis
REDIS_TTL=
REDIS_USERNAME=
REDIS_PASSWORD=
REDIS_HOST=
REDIS_PORT=
REDIS_URI=

# rabbitmq
#REDIS_URI=


# rabbitmq
RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=
RABBITMQ_URI=
RABBITMQ_EXCHANGE=
RABBITMQ_QUEUE=
RABBITMQ_DEFAULT_PREFETCH=
RABBITMQ_URI=

#sentry

#sentry
SENTRY_DSN=
SENTRY_ENVIRONMENT=

#google ouath
#google ouath
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_CALLBACK_URL=

#facebook ouath


#facebook ouath
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
FACEBOOK_CALLBACK_URL=

#throttle

#throttle
THROTTLE_LIMIT=
THROTTLE_TTL=

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"@nestjs/cli": "10.1.18",
"@nestjs/schematics": "10.0.2",
"@nestjs/testing": "10.2.7",
"@rubiin/eslint-config": "^1.8.8",
"@rubiin/eslint-config": "^1.8.10",
"@rubiin/tsconfig": "^1.1.0",
"@sentry/types": "^7.73.0",
"@side/jest-runtime": "^1.1.0",
Expand Down
5 changes: 5 additions & 0 deletions src/common/@types/enums/misc.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export enum RoutingKey {
SEND_NEWSLETTER = "send-newsletter",
}

export enum Queues {
MAIL = "mail",
HTTP = "http",
}

export enum PaginationType {
OFFSET = "OFFSET",
CURSOR = "CURSOR",
Expand Down
2 changes: 0 additions & 2 deletions src/common/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ declare global {
REDIS_PORT: number

RABBITMQ_URI: string
RABBITMQ_EXCHANGE: string
RABBITMQ_QUEUE: string
RABBITMQ_DEFAULT_PREFETCH: number

SENTRY_DSN: string
Expand Down
2 changes: 0 additions & 2 deletions src/lib/config/configs/rabbitmq.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { RABBIT_MQ_URI_REGEX } from "@common/constant";
export const rabbitmqConfigValidationSchema = {
RABBITMQ_URI: Joi.string().pattern(RABBIT_MQ_URI_REGEX).required(),
RABBITMQ_EXCHANGE: Joi.string().required(),
RABBITMQ_QUEUE: Joi.string().required(),
RABBITMQ_DEFAULT_PREFETCH: Joi.number().required(),
};

export const rabbitmq = registerAs("rabbitmq", () => ({
url: process.env.RABBITMQ_URI,
exchange: process.env.RABBITMQ_EXCHANGE,
queue: process.env.RABBITMQ_QUEUE,
prefetchCount: process.env.RABBITMQ_DEFAULT_PREFETCH,
}));
38 changes: 0 additions & 38 deletions src/lib/mailer/mail.processor.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/lib/mailer/mailer.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { OnModuleInit } from "@nestjs/common";
import { Module } from "@nestjs/common";
import { ConfigurableModuleClass } from "./mail.module-definition";
import { MailProcessor } from "./mail.processor";
import { MailerService } from "./mailer.service";

@Module({
providers: [MailerService, MailProcessor],
exports: [MailerService, MailProcessor],
providers: [MailerService],
exports: [MailerService],
})
export class MailModule extends ConfigurableModuleClass implements OnModuleInit {
constructor(private readonly mailService: MailerService) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/rabbit/rabbit.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RabbitMQModule } from "@golevelup/nestjs-rabbitmq";
import { Global, Logger, Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { RabbitService } from "./rabbit.service";
import { RabbitMQHealthCheckService } from "./healthcheck";

const logger = new Logger("RabbitMQ");

Expand Down
6 changes: 3 additions & 3 deletions src/lib/rabbit/rabbit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RabbitSubscribe } from "@golevelup/nestjs-rabbitmq";
import { Injectable, Logger } from "@nestjs/common";
import { from, map, tap } from "rxjs";
import { MailerService } from "@lib/mailer/mailer.service";
import { MailPayload, RoutingKey } from "@common/@types";
import { MailPayload, Queues, RoutingKey } from "@common/@types";

@Injectable()
export class RabbitService {
Expand All @@ -12,9 +12,9 @@ export class RabbitService {
constructor(private readonly mailService: MailerService) {}

@RabbitSubscribe({
routingKey: [RoutingKey.SEND_MAIL, RoutingKey.SEND_NEWSLETTER],
routingKey: RoutingKey.SEND_MAIL,
exchange: process.env.RABBITMQ_EXCHANGE,
queue: process.env.RABBITMQ_QUEUE,
queue: Queues.MAIL,
})
sendMail(payload: MailPayload) {
return from(
Expand Down
2 changes: 1 addition & 1 deletion src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { Observable } from "rxjs";
import { from, map, mergeMap, of, switchMap, throwError } from "rxjs";

import type {
RecordWithFile,
PaginationResponse,
RecordWithFile,
} from "@common/@types";
import {
CursorType,
Expand Down

0 comments on commit ba2c8b1

Please sign in to comment.