我有一个函数可以接收参数时间戳并将其发送到队列,在消费者从队列中获取此时间戳并将其与第一次调用时参数中的时间戳进行比较之后,每次调用都可以,但在下一次调用时,消费者从队列中接收新时间戳但 stile使用参数中的先前时间戳进行比较
例如:
第一次调用 => 传递给函数的时间戳 = 123 ,来自参数的时间戳 = 123,来自队列的时间戳 = 123
调用 2 => 传递给函数的时间戳 = 456,来自参数的时间戳 = 123,来自队列的时间戳 = 456
public async checkQueue (timestamp: number): Promise<void> {
try {
const content = Buffer.from(timestamp);
this.channel.sendToQueue(this.technicalQueueName, content);
await this.channel.consume(this.technicalQueueName, (message: Message | null): void => {
this.channel.ack(message);
if (Number(message.content.toString()) !== timestamp) {
await this.channel.deleteQueue(this.technicalQueueName);
throw new AppError('INVALID MESSAGE', 'Invalid message');
}
});
} catch (error) {
await this.channel.deleteQueue(this.technicalQueueName);
throw new AppError('HEALTHCHECK ERROR', error.message, error, undefined);
}
}
我知道心跳,我真的需要通过时间戳来实现它)