I am using a subscribe function in a nestjs service to receive rabbit messages.
@RabbitSubscribe({
exchange: 'test'.
routingKey: 'test',
queue: 'q'
})
async handleEvent( msg: msgModel) {
console.log(message)
}
I have multiple subscribers set up like this and I want to implement model validation similar to what we do in controllers with validationPipe()
However, the validationPipe() or guard does not work on a simple service.
Therefore, I am looking to create a custom decorator that can validate the message received.
Something along these lines:
@CustomDec(msg)
@RabbitSubscribe({
exchange: 'test'.
routingKey: 'test',
queue: 'q'
})
async handleEvent( msg: msgModel) {
console.log(message)
}
or
@RabbitSubscribe({
exchange: 'test'.
routingKey: 'test',
queue: 'q'
})
async handleEvent( @customDec() msg: msgModel) {
console.log(message)
}
Is it feasible to achieve this?