From 0fb0b09899d4dc188c4f8642e1b835bcc0c736c1 Mon Sep 17 00:00:00 2001 From: Alvar San Martin Date: Tue, 3 Feb 2026 16:39:34 +0100 Subject: [PATCH] Bug bucle infinito de mensajes delay <-> cola --- docs/sim-api/Activate.bru | 3 ++- .../shared/infrastructure/RabbitMQEventBus.ts | 16 +++++++++++++++- packages/sim-consumidor-objenious/.env | 4 ++-- .../aplication/Sim.controller.ts | 5 ++++- .../aplication/Sim.controller.ts | 4 +--- .../aplication/Sim.usecases.ts | 2 +- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/sim-api/Activate.bru b/docs/sim-api/Activate.bru index 826582c..3a76bda 100644 --- a/docs/sim-api/Activate.bru +++ b/docs/sim-api/Activate.bru @@ -11,7 +11,8 @@ post { } body:form-urlencoded { - iccid: 8933201124059175967 + iccid: 8933201124059176320 + offer: SAVEFAMILY1 } settings { diff --git a/packages/shared/infrastructure/RabbitMQEventBus.ts b/packages/shared/infrastructure/RabbitMQEventBus.ts index fde9bab..df996db 100644 --- a/packages/shared/infrastructure/RabbitMQEventBus.ts +++ b/packages/shared/infrastructure/RabbitMQEventBus.ts @@ -38,14 +38,21 @@ export class RabbitMQEventBus implements EventBus { return this.channel.ack(msg) } + /** + * TODO: + * - Esta implementacion del nack debe estar en objenious + */ async nack(msg: ConsumeMessage, requeue?: boolean) { if (this.channel == undefined) throw new Error("[RMQ] Canal no iniciallizado"); + console.log("NACK: ", msg.properties.headers) + const headers = msg.properties.headers || {} const numberRetry = headers['x-retry-count'] || 0 const routingKey = msg.fields.routingKey if (numberRetry < this.maxRetry) { + console.log("Dalaying") await this.channel.publish("sim.ex.objenious.delayed", routingKey, msg.content, { headers: { ...headers, @@ -53,6 +60,7 @@ export class RabbitMQEventBus implements EventBus { } }) } else { + console.log("DeadLetter") await this.channel.publish("sim.ex.objenious.dlx", routingKey, msg.content, { headers: { ...headers @@ -60,6 +68,8 @@ export class RabbitMQEventBus implements EventBus { }) } + // Hace falta? + this.channel.ack(msg) //return this.channel.nack(msg, false, requeue) } @@ -100,7 +110,11 @@ export class RabbitMQEventBus implements EventBus { const routingKey = event.key const content = Buffer.from(JSON.stringify(event)) this.channel?.publish(exchange, routingKey, content, {}, (err, ok) => { - console.log("Confirmacion", err, ok) + if (err == undefined) { + console.log("Evento publicado ", event) + } else { + console.error("Error publicando", event) + } }) } return res() diff --git a/packages/sim-consumidor-objenious/.env b/packages/sim-consumidor-objenious/.env index 919cf75..7fc2c5a 100644 --- a/packages/sim-consumidor-objenious/.env +++ b/packages/sim-consumidor-objenious/.env @@ -4,5 +4,5 @@ OBJ_AUTHORIZATION=XOc7FtwXD8hUX2SFVX94XSty8wkOmChkwDNF09O_aIxPubMDdFUdCDCB4zpzSI OBJ_CLI_ASSERTION=XOc7FtwXD8hUX2SFVX94XSty8wkOmChkwDNF09O_aIxPubMDdFUdCDCB4zpzSIxi8nOcTg7r_LM_nmd5qm7uLbksf_XArjI8iAyhjKz_2BAXPhmvKs4Fc9f3vv5LDfCVrPB9lP8P7rJ66_qnWs4jvhLQxSfn29m96hgXeCf8oySdIDUjN2q9Js3KAS5LL52Ri6ryvUeO1PvMhaPQMWRqoHIqTV1wPfPtiqQwcjUPmu5GeW164Kq1JLgV3KaGzfCZ9Qv9lbv30EJrukXxWuLCAhBS0kzrBXZoWvf2pb9uh3Am_93_dDxiIGQfIap9ZU_m8ZD1HPgvZOMCY6ZkxQconQ OBJ_CLIENT_ID=savefamily_rest_ws OBJ_KID=xNfbMiyL1ORXGP8lElhcv8nVaG3EJKye4Lc1YoN3I1E -OBJ_BASE_URL=https://api-getway.objenious.com/ws -//OBJ_BASE_URL=https://api-getway.objenious.com/ws/test +//OBJ_BASE_URL=https://api-getway.objenious.com/ws +OBJ_BASE_URL=https://api-getway.objenious.com/ws/test diff --git a/packages/sim-consumidor-objenious/aplication/Sim.controller.ts b/packages/sim-consumidor-objenious/aplication/Sim.controller.ts index 970ba27..77f6b68 100644 --- a/packages/sim-consumidor-objenious/aplication/Sim.controller.ts +++ b/packages/sim-consumidor-objenious/aplication/Sim.controller.ts @@ -76,7 +76,10 @@ export class SimController { const iccid = msgData.payload.iccid const offer = msgData.payload.offer - if (offer == undefined) throw new Error("Error activando la sim, no se ha especificado la oferta") + if (offer == undefined) { + this.eventBus.nack(msg) + throw new Error("Error activando la sim, no se ha especificado la oferta") + } this.tryUseCase(msg, this.useCases.activate({ dueDate: this.genDueDate(2 * 60).toISOString(), diff --git a/packages/sim-entrada-eventos/aplication/Sim.controller.ts b/packages/sim-entrada-eventos/aplication/Sim.controller.ts index 41ef851..47a27b1 100644 --- a/packages/sim-entrada-eventos/aplication/Sim.controller.ts +++ b/packages/sim-entrada-eventos/aplication/Sim.controller.ts @@ -66,8 +66,6 @@ export class SimController { const { iccid, offer } = req.body - //TODO: incluir lo de las offers - const compañia = this.compañiaFromIccid(iccid) if (compañia == undefined) { @@ -81,7 +79,7 @@ export class SimController { try { - await this.simUseCases.activation({ iccid, compañia }) + await this.simUseCases.activation({ iccid, compañia, offer }) res.status(200).json({ iccid: iccid, diff --git a/packages/sim-entrada-eventos/aplication/Sim.usecases.ts b/packages/sim-entrada-eventos/aplication/Sim.usecases.ts index 195d19b..460ffc6 100644 --- a/packages/sim-entrada-eventos/aplication/Sim.usecases.ts +++ b/packages/sim-entrada-eventos/aplication/Sim.usecases.ts @@ -34,7 +34,7 @@ export class SimUsecases { return this.eventBus.publish([activationEvent]) } - async activation(args: { iccid: string, compañia: string, offer?: string }) { + async activation(args: { iccid: string, compañia: string, offer: string }) { const activationEvent = { key: `sim.${args.compañia}.activate`,