Closed thekvn closed 3 years ago
Hello! Thanks for using it. Library acknowledge messages automatically when RMQRoute where message is processed returns
, so you don't need to do it manually.
We want to handle ack manually
Can you describe a usecase for manual ack?
We want to we explicit about whether we ack a message or not. This is so we can ensure messages are re-queued and re-delivered for messages we failed to process.
For example, we might have a queue for performing email deliveries, we would only want to ack when email delivery was successful, or if an email delivery was unsuccessful after N redelivery attempts, in this case we want to use nAck
@thekvn, message will be re-queued and re-delivered if your RMQRoute will throw an Exception. In you case you should return from route only if delivery is successful, and if not, throw an exception (or add additional retries before it). This way your message will return to queue. Will it solve your problem? The mail goal of this library is to provide simple pattern for RPC. Manual message ack will lead to additional complexity.
@AlariCode from what I see, throwing in EventRoute either return an error for send
or ack message for notify. I assume, @thekvn case is about notify
.
I also think that @thekvn functionality is a need and got 2 ideas:
throw new NoAckError()
@mjarmoc
@thekvn, @mjarmoc thanks for your patience! I added two new features to nestjs-rmq 1.13.0.
Message
with @RMQMessage
decorator, that not only contains contents, but all its metadata.import { RMQController, RMQRoute, Validate, RMQMessage, ExtendedMessage } from 'nestjs-rmq';
@RMQRoute('my.rpc')
myMethod(data: myClass, @RMQMessage msg: ExtendedMessage): number {
// ...
}
this.rmqService.ack(msg);
@RMQRoute
option manualAck
.
@RMQRoute('my.rpc', { manualAck: true })
myMethod(data: myClass, @RMQMessage msg: ExtendedMessage): number {
}
So if you want to manually ack message:
```typescript
@RMQRoute('my.rpc', { manualAck: true })
myMethod(data: myClass, @RMQMessage msg: ExtendedMessage): number {
// Any logic goes here
this.rmqService.ack(msg);
// Any logic goes here
}
Will this solve your case? @mjarmoc thx for decorator idea!
One small addition before closing issue. In 1.14.0 I added ExtendedMessage
so you can use additional debug method. Now usage is
myMethod(data: myClass, @RMQMessage msg: ExtendedMessage): number {
Hello, great library, I couldn't find it in the docs, how do you acknowledge messages in handlers with this library?