From f7f22de65c5f8952c2b98770cf7c1e5783009970 Mon Sep 17 00:00:00 2001 From: Abdalhamid Alhamad Date: Wed, 4 Feb 2026 15:05:55 +0300 Subject: [PATCH] feat(allowance): add dead letter exchange to allowance queue configuration - Introduced ALLOWANCE_RETRY_EXCHANGE for handling message retries in the allowance worker service. - Updated queue assertion to include dead letter exchange and routing key for improved message processing reliability. --- src/allowance/services/allowance-worker.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/allowance/services/allowance-worker.service.ts b/src/allowance/services/allowance-worker.service.ts index 03d1f4b..b7326e2 100644 --- a/src/allowance/services/allowance-worker.service.ts +++ b/src/allowance/services/allowance-worker.service.ts @@ -5,7 +5,7 @@ import moment from 'moment'; import { CardService } from '~/card/services'; import { AllowanceScheduleRepository } from '../repositories/allowance-schedule.repository'; import { AllowanceCreditRepository } from '../repositories/allowance-credit.repository'; -import { ALLOWANCE_DLQ_EXCHANGE, ALLOWANCE_QUEUE_NAME } from '../constants'; +import { ALLOWANCE_DLQ_EXCHANGE, ALLOWANCE_QUEUE_NAME, ALLOWANCE_RETRY_EXCHANGE } from '../constants'; import { AllowanceFrequency, AllowanceScheduleStatus } from '../enums'; type AllowanceQueuePayload = { @@ -53,7 +53,11 @@ export class AllowanceWorkerService implements OnModuleInit, OnModuleDestroy { }); this.channel = this.connection.createChannel({ setup: async (channel: any) => { - await channel.assertQueue(this.queueName, { durable: true }); + await channel.assertQueue(this.queueName, { + durable: true, + deadLetterExchange: ALLOWANCE_RETRY_EXCHANGE, + deadLetterRoutingKey: this.queueName, + }); await channel.prefetch(10); await channel.consume(this.queueName, (msg: any) => this.handleMessage(channel, msg), { noAck: false,