Cola con delay -> cola dead letter
This commit is contained in:
@@ -20,43 +20,50 @@ export const rmqConnOptions = <RMQConnectionParams>{
|
||||
|
||||
export const rabbitmqEventBus = new RabbitMQEventBus({
|
||||
connectionParams: rmqConnOptions,
|
||||
buildStructure: buildQueues
|
||||
buildStructure: buildQueues,
|
||||
maxRetry: 5
|
||||
})
|
||||
|
||||
function buildQueues(channel: Channel) {
|
||||
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)
|
||||
})
|
||||
async function buildQueues(channel: Channel) {
|
||||
const QUEUES = {
|
||||
OBJ: "sim.objenious",
|
||||
DLX: "sim.objenious.dlx",
|
||||
DEL: "sim.objenious.delayed"
|
||||
}
|
||||
|
||||
const EXCHANGES = {
|
||||
MAIN: "sim.exchange",
|
||||
DLX: "sim.ex.objenious.dlx",
|
||||
DEL: "sim.ex.objenious.delayed"
|
||||
}
|
||||
|
||||
channel?.assertQueue("sim.objenious.dlx")
|
||||
.then(e => {
|
||||
console.log("[o] Creada la cola " + e.queue)
|
||||
const DELAY = 10 * 1000
|
||||
const BASE_OBENIOUS_KEY = "sim.objenious.#"
|
||||
|
||||
await channel.assertExchange(EXCHANGES.DEL, "topic")
|
||||
await channel.assertExchange(EXCHANGES.DLX, "topic")
|
||||
await channel.assertExchange(EXCHANGES.MAIN, "topic")
|
||||
|
||||
await channel.assertQueue(QUEUES.OBJ)
|
||||
await channel.assertQueue(QUEUES.DLX)
|
||||
await channel.assertQueue(QUEUES.DEL, {
|
||||
durable: true,
|
||||
arguments: {
|
||||
'x-message-ttl': DELAY,
|
||||
'x-dead-letter-exchange': EXCHANGES.MAIN,
|
||||
}
|
||||
})
|
||||
|
||||
// Cola dead-letter
|
||||
await channel.bindQueue(QUEUES.DLX, EXCHANGES.DLX, "sim.objenious.#")
|
||||
// Cola delay
|
||||
await channel.bindQueue(QUEUES.DEL, EXCHANGES.DEL, BASE_OBENIOUS_KEY)
|
||||
// Cola objenious -> main exchange
|
||||
await channel.bindQueue(QUEUES.OBJ, EXCHANGES.MAIN, BASE_OBENIOUS_KEY)
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export async function startRMQClient() {
|
||||
await rabbitmqEventBus.connect()
|
||||
return rabbitmqEventBus
|
||||
|
||||
Reference in New Issue
Block a user