nats-io / nats.java

Java client for NATS
Apache License 2.0
563 stars 153 forks source link

Making JetStreamReader more robust #1164

Closed roeschter closed 2 months ago

roeschter commented 2 months ago

Issue, when the reader receivers fewer messages than expected in a pull, it will eventually stall. Most easily reproduced with a server restart/reconnect.

Not sure whether we consider this a bug. Maybe make it a feature request.

scottf commented 2 months ago

Can you please provide some example code or a unit test to demonstrate this?

scottf commented 2 months ago

Also, can you look at "simplification", i.e. using the ConsumerContext to consumer messages. It's very robust and probably does what you need. There are examples here: https://github.com/nats-io/nats.java/tree/main/src/examples/java/io/nats/examples/jetstream/simple

roeschter commented 2 months ago

+ConsumerContext does not have this issue - recovers after timeout -Seems ConsumerContext suffers from the same issue:

To reproduce:

  1. Run either of the two below - standard JS enabled NATS server on localhost
  2. Stop the server and restart immediately
  3. etStreamReader is not recovering
  4. Make the suggested change for JetStreamReader - should recover after the timeout set in the request.

Please check my Playground - https://github.com/roeschter/natsPlayground - you should have seen an invite See the /reproducer package

roeschter commented 2 months ago

Correction: ConsumerContext self recovers after timeout - The default is 30s, I did not wait that long.