Skip to content

Is it possible to avoid JS.API.STREAM.NAMES request during kv.watch? #389

Answered by aricart
sdkmdsdkmsfmm asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, watch() creates a consumer under the covers, which then matches the stream by looking at the subject, thus the call to list the streams, so that means that you cannot really bind to the consumer to observe changes. Streams in general now have a republish option that allows mapping messages, this means that you can use core NATS to learn if there was an update to the KV - of course, this will only work if the client is listening, but on startup, you can learn the current value and then respond to the changes. You can then allow the client to subscribe to the specific keys you want them to be able to observe.

Here's an example https://github.com/nats-io/nats.deno/blob/main/te…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aricart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants