nats-io / nats.net.v2

Full Async C# / .NET client for NATS

Home Page:https://nats-io.github.io/nats.net.v2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KV ResumeAtRevision option for watches

mtmk opened this issue · comments

@mtmk as per slack conversation, I'll like to give this one a shot.

Initial idea:

NatsKvOpts.cs
Would add ResumeAtRevision int prop to NatsKVWatchOpts (document it to be "The revision to start from, if set to 0 (default) this will be ignored"

public Func<CancellationToken, ValueTask<bool>>? OnNoData { get; init; }

NatsKVWatcher.cs
It's using the _sequenceStream here

var sequence = Volatile.Read(ref _sequenceStream);

And I was thinking about setting _sequenceStream = opts.ResumeAtRevision here https://github.com/nats-io/nats.net.v2/blob/main/src/NATS.Client.KeyValueStore/Internal/NatsKVWatcher.cs#L78

commented

@niklasfp looking at this a bit closer I think it's good. Setting the _sequenceStream = opts.ResumeAtRevision in NatsKVWatcher.ctor should work since it will treacle down to the consumer create request down below and also should be updated as expected on reconnects. feel free to open a PR when you're ready and have time. thank you 💯

@niklasfp looking at this a bit closer I think it's good. Setting the _sequenceStream = opts.ResumeAtRevision in NatsKVWatcher.ctor should work since it will treacle down to the consumer create request down below and also should be updated as expected on reconnects. feel free to open a PR when you're ready and have time. thank you 💯

For future reference and history, setting the sequence in the ctor was not an option because of the way watchers gets re-created.