2026-01-16 11:14:35 +01:00
|
|
|
import { RabbitMQEventBus, RMQConnectionParams } from "#shared/infrastructure/RabbitMQEventBus"
|
2026-01-28 10:25:49 +01:00
|
|
|
import { Channel } from "amqp-connection-manager"
|
2026-01-16 11:14:35 +01:00
|
|
|
import { env } from "./env"
|
|
|
|
|
|
|
|
|
|
const rmqUser = env.RABBITMQ_USER
|
|
|
|
|
const rmqPass = env.RABBITMQ_PASSWORD
|
|
|
|
|
const rmqHost = env.RABBITMQ_HOST
|
|
|
|
|
const rmqPort = Number(env.RABBITMQ_PORT)
|
|
|
|
|
const rmqSecure = false
|
|
|
|
|
const rmqVhost = env.RABBITMQ_VHOST
|
|
|
|
|
|
|
|
|
|
export const rmqConnOptions = <RMQConnectionParams>{
|
|
|
|
|
username: rmqUser,
|
|
|
|
|
password: rmqPass,
|
|
|
|
|
vhost: rmqVhost,
|
|
|
|
|
hostname: rmqHost,
|
|
|
|
|
port: rmqPort,
|
|
|
|
|
secure: rmqSecure,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const rabbitmqEventBus = new RabbitMQEventBus({
|
2026-01-28 10:25:49 +01:00
|
|
|
connectionParams: rmqConnOptions,
|
|
|
|
|
buildStructure: buildQueues
|
2026-01-16 11:14:35 +01:00
|
|
|
})
|
|
|
|
|
|
2026-01-28 10:25:49 +01:00
|
|
|
function buildQueues(channel: Channel) {
|
2026-01-27 15:12:41 +01:00
|
|
|
channel?.assertQueue("sim.objenious")
|
|
|
|
|
.then(e => {
|
|
|
|
|
console.log("[o] Creada la cola " + e.queue)
|
|
|
|
|
channel?.bindQueue("sim.objenious", "sim.exchange", "sim.objenious.*")
|
|
|
|
|
.then(e => {
|
|
|
|
|
console.log("[o] Bindeada la cola sim.objenious a sim.exchange ")
|
|
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
channel?.assertQueue("sim.objenious.dlx")
|
|
|
|
|
.then(e => {
|
|
|
|
|
console.log("[o] Creada la cola " + e.queue)
|
|
|
|
|
|
|
|
|
|
channel?.bindQueue("sim.objenious.dlx", "sim.dlx", "sim.objenious.*")
|
|
|
|
|
.then(e => {
|
|
|
|
|
console.log("[o] Bindeada la cola sim.objenious.dlx a sim.dlx")
|
|
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.catch(e => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
})
|
2026-01-28 10:25:49 +01:00
|
|
|
}
|
2026-01-27 15:12:41 +01:00
|
|
|
|
2026-01-28 10:25:49 +01:00
|
|
|
export async function startRMQClient() {
|
|
|
|
|
await rabbitmqEventBus.connect()
|
2026-01-16 11:14:35 +01:00
|
|
|
return rabbitmqEventBus
|
|
|
|
|
}
|