Programatically getting all messages from a JetStream stream
See original GitHub issueWhat would a reasonable way of doing the same as nats str view streamName --subject filter_subject
programmatically be?
I’ve been using JetStreamManager.streams.info(streamName)
to get the number of messages in the stream to then use jetstreamClient.fetch(streamName, temporaryDurableConsumerThatUsesFilterSubject, { batch: numberOfMessagesInStream, no_wait: true})
to get to all messages.
And after this, deleting the temporaryDurableConsumerThatUsesFilterSubject
Are there any dangers that might not be obvious in doing this, or is this a reasonable approach?
This is to enable projections over a specific stream, for example: users.someUserId that has a message of type Registered, and then EmailConfirmed from which I can “project” {hasUserConfirmedEmail: true}
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (7 by maintainers)
Top GitHub Comments
You probably dont want to pull the full stream in one go as it could overwhelm our client. Do it in batches of 10 or whatever.
Using a durable is annoying, but its the only way we can do pull.
Just experienced an instance where num_pending in the consumer is 0 when there are actual messages,
last_active
really does seem like the only option which is unfortunate. Here’s the consumer info: