question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Programatically getting all messages from a JetStream stream

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ripienaarcommented, Dec 9, 2021

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.

0reactions
ruidfigueiredocommented, Dec 14, 2021

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:

subscription consumerInfo: {
  type: 'io.nats.jetstream.api.v1.consumer_info_response',
  stream_name: 'dev-check-audio-spam',
  name: 'qmXnZGeU',
  created: '2021-12-14T15:14:14.93922231Z',
  config: {
    deliver_subject: '_INBOX.CHND2NFODYEGAGELC0W4K5',
    deliver_policy: 'all',
    ack_policy: 'none',
    ack_wait: 79200000000000,
    max_deliver: 1,
    filter_subject: 'dev.check-audio-spam.61b8b292899bc00029201488.file',
    replay_policy: 'instant',
    idle_heartbeat: 5000000000,
    flow_control: true
  },
  delivered: {
    consumer_seq: 16,
    stream_seq: 2208,
    last_active: '2021-12-14T15:14:14.941194031Z'
  },
  ack_floor: { consumer_seq: 16, stream_seq: 2204 },
  num_ack_pending: 0,
  num_redelivered: 0,
  num_waiting: 0,
  num_pending: 0,
  cluster: { name: 'nats', leader: '....' },
  push_bound: true
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

JetStream wire API Reference - NATS Docs
The normal way to use JetStream is through the NATS client libraries which expose a set of JetStream functions that you can use...
Read more >
JetStream - GitHub
JetStream stores messages in streams. A stream defines how messages are stored and how long they persist. To store a message in JetStream,...
Read more >
JetStream: The Next Generation Of NATS Persistence Engine
JetStream is the next generation of NATS Streaming. Unlike its predecessor, all JetStream's persistency features are built directly into ...
Read more >
c# - JetStream: How to make Push Subscription with Durable ...
I try to make Durable and Delivery consumer, but i get "No Interest" as result. It is "Active" When i create PushSubscribeOptions like...
Read more >
Using NATS JetStream Key/Value Store in Go - Medium
The NATS JetSteam, the persistence layer of NATS, provides a distributed streaming platform that lets you capture streams of messages ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found