Cola con delay -> cola dead letter
This commit is contained in:
@@ -2,6 +2,8 @@ import { EventBus } from "#shared/domain/EventBus.port";
|
||||
import { ConsumeMessage } from "amqplib";
|
||||
import { SimUseCases } from "./Sim.usecases";
|
||||
import { SimEvents } from "#shared/domain/SimEvents";
|
||||
import { constants } from "node:buffer";
|
||||
import { constrainedMemory } from "node:process";
|
||||
|
||||
/**
|
||||
* La clase usa generadores de funciones para mantener el contexto
|
||||
@@ -47,23 +49,35 @@ export class SimController {
|
||||
}
|
||||
const msgData = this.decodeMsg(msg) as SimEvents.activation
|
||||
|
||||
if (msgData == undefined || msgData.payload == undefined) Promise.reject("Mensaje invalido")
|
||||
if (msgData == undefined || msgData.payload == undefined) throw new Error("Mensaje invalido")
|
||||
console.log("Mensaje procesado", msgData?.toString())
|
||||
|
||||
// TODO: Añadir un validador del mensaje
|
||||
|
||||
const iccid = msgData.payload.iccid
|
||||
|
||||
const headers = msg.properties.headers
|
||||
console.log("HEADERS: ", headers)
|
||||
|
||||
try {
|
||||
// Caso de uso de activaciones
|
||||
await this.useCases.activate({
|
||||
const result = await this.useCases.activate({
|
||||
dueDate: this.genDueDate(2 * 60).toISOString(),
|
||||
identifier: {
|
||||
identifierType: "ICCID",
|
||||
identifiers: [iccid]
|
||||
}
|
||||
})()
|
||||
this.eventBus.ack(msg)
|
||||
|
||||
console.log("Resultado de la peticion", result)
|
||||
|
||||
if (result.error == undefined) {
|
||||
console.log("Ack", msgData)
|
||||
await this.eventBus.ack(msg)
|
||||
} else {
|
||||
console.log("Nack", msgData)
|
||||
await this.eventBus.nack(msg)
|
||||
}
|
||||
} catch (e) {
|
||||
this.eventBus.nack(msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user