I'm currently working on a function in TypeScript to consume messages from my RabbitMQ:
async consume(
queue: string,
callback: (message: ConsumeMessage | null) => void,
) {
return this.channel.consume(queue, message => {
callback(message);
this.channel.ack(message);
});
}
The this.channel.consume
method takes the queue and a message with type ConsumeMessage
, while this.channel.ack
requires a Message
type parameter from the amqlib library.
However, I ran into an issue where I get an error stating:
Argument of type 'ConsumeMessage | null' is not assignable to parameter of type 'Message'. Type 'null' is not assignable to type 'Message'.ts (2345)
whenever I try to use .ack
.
I also have questions about how to handle errors effectively in this scenario.