如果我在NestJS应用程序中使用NATS进行异步通信,是否有一种手动确认消息的方法?这是非常常见的用例,在完成服务处理后消息被确认。如果消息未被确认,服务器将需要重新传递(就像旧NATS流库中的一样)。
@EventPattern({ cmd: 'user:create' })
async createUser(@Payload() user: UserDto, @Ctx() context: NatsContext) {
await this.emailsService.sendWelcomeEmail(user)
// need to manually acknowledge the message here but the docs do not provide a way to do so.
}发布于 2022-02-07 18:09:34
当使用nats流https://www.npmjs.com/package/@nestjs-plugins/nestjs-nats-streaming-transport时
@EventPattern(Patterns.UserCreated)
public async stationCreatedHandler(@Payload() data: { id: number, name: string }, @Ctx() context: NatsStreamingContext) {
console.log(`received message: ${JSON.stringify(data)}`)
context.message.ack()
}
//setup
{
durableName: 'user-queue-group',
manualAckMode: true,
deliverAllAvailable: true,
} /* TransportSubscriptionOptions */ ,
),https://stackoverflow.com/questions/70317945
复制相似问题