Add bulk message ack/nak #302
Replies: 3 comments 1 reply
-
Hey! Thanks for the proposal and effort to write it down. Let's address few points:
Because of above, I do not think its a good idea to implement what you are suggesting. Feel encouraged to discuss it further. |
Beta Was this translation helpful? Give feedback.
-
I've converted this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Ok. Perhaps this is an opportunity to improve the stream consumer documentation and/or the various clients' JetStream APIs, because my experience configuring JetStream consumers (using It appears to me that there are only so many factors when it comes to consumers:
I'm also wondering how the type of stream affects these choices as well; I'm referring specifically to streams with the three different It surprises me that you assert that ordered consumers inherently use My use case is that I want to primarily use pull consumers to implement CQRS event projectors that are receiving events from a stream that represents an event bus. Some projector types are simply writing the events themselves to a database, some are updating counts, averages, etc to projections, and some are calling third-party partners' systems, etc. These are the features that I've identified for these three types of projectors.
As you can see, I'm unsure about durability. We're operating in a clustered environment, so that we have multiple instances of identical projector types at any given time available to process batches of messages. In our projector use cases, we don't want to miss any messages, so I conclude that they should all be durable. If I'm incorrect, please explain why. Also, if a projector type pulls a batch of, say, 100 messages, successfully processes 63 of them and then encounters an error, I expected to ack the first 63 messages so that they're not redelivered to any other projector instances of the same type, but if you're saying that messages are not acked, then I don't understand. Perhaps the docs should enumerate each of these nine permutations of push/pull, ephemeral/durable, and ordered/unordered individually and describe how they should be configured and whether they're nonsensical. Further, I'd think it pretty simple if the client APIs had simpler, high-level APIs for each of these permutations to simplify writing consumers. In the case of
Thanks in advance for setting me straight. NB: while the video at https://docs.nats.io/nats-concepts/jetstream/consumers#persistence-durable-ephemeral was informative, I guess it wasn't enough for me to master consumer configurations. |
Beta Was this translation helpful? Give feedback.
-
Proposed change
NB: I asked this question in the #general channel of the Slack channel, but didn't seem to get much traction. The proposed methods are slightly different than in the Slack messages after some more thought.
For those use cases where we don't know at design time which
AckPolicy
we want to use, we'd like for there to be more efficient bulk acking/naking APIs onFetchConsumer
. These are intended primarily for ordered pull consumers. We propose the following new interface methods.default void ackAll() { ackAll(true); }
default void nakAll() { ackAll(false); }
default void ackAll(boolean ack) { ack(-1, ack); }
-- acks all messages in one server round trip, similar toAckPolicy.All
void ack(int n, boolean ack) { ack(n, ack, false); }
-- acks first n messages (all if n < 0) of the batch in one server round tripvoid ackThenNak(int n);
-- acks first n messages (all if n < 0) then naks the rest in one server round tripIf it's inappropriate for these methods to be placed on
FetchConsumer
, perhaps a new set of batch APIs could be created onConsumerContext
to support batches ofMessage
s, likeBatchConsumer fetchBatch(int maxMessages);
BatchConsumer fetchBatch(int maxBytes);
BatchConsumer fetchBatch(BatchConsumeOptions opts);
where
BatchConsumer
might be something likeUse case
The use case is when it's not known at design time which
AckPolicy
should be used, and the developer doesn't want to ack or nak eachMessage
individually.Beta Was this translation helpful? Give feedback.
All reactions