我正在收集来自 Pubsub 主题的消息。主要思想是对我收到的每条消息执行一些逻辑(在 DB 中插入一些内容)。我的问题是这个。
在我完成逻辑之后,我想放置一个message.ack()
方法来告诉 pubsub“好的,这条消息完成了!”。我的问题是我想去“黑暗的一面”,如果有人失败,请转到我的位置message.nack()
说“好吧,发布订阅,我们有问题,我不承认这个消息,所以让我们继续其余的”
但它不断抛出这个错误,不要继续其他消息。
我能做什么?
控制器:
@EventPattern('topicName')
async extractMessageTopic(msg: Message) {
try {
console.log("--Iniciando--");
await this.appService.extractMessageTopic(msg)
msg.ack() //Acknoledge the message
} catch (error) {
console.log("Error primera capa!", error);
msg.nack()//If any error, dont acknoledge
}
}
}
服务:
async extractMessageTopic(msg: Message) {
const buf = Buffer.from(msg.data)
const dataObject: any = JSON.parse(buf.toString())
console.log("Mensaje -> ", dataObject);
console.log("------------");
//Inserto En shipment
//const shipId = await this.shipmentRepositoryService.insert(dataObject)
//Inserto en Orders
//Inserto en Lines
}
谢谢!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句