Skip to content

Problem with consuming messages on demand by batches #749

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

You must be logged in to vote

The correct use for you use is fetch() - Fetch will start giving you messages instantly and will wait for additional messages to arrive if you asked for more than it is available - the reason for the wait is that otherwise you'll continue to ask the server for more messages, when it has none. The mitigating case for you is that want to buffer, but bail out early. If you look at the num pending you can decide to continue or stop your loop. If you don't get any messages there's nothing for you to process, so the call will silently wait for messages.

Here's something that does what you are asking

import { connect, delay, nanos, nuid } from "@nats-io/transport-node";
import { AckPolicy, jetst…

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