Giter Club home page Giter Club logo

Comments (5)

piotrpio avatar piotrpio commented on August 23, 2024

Hello @kung-foo, thanks for reporting the issue. I'm looking at this (and #1462) and will update you when I have a fix.

from nats.go.

piotrpio avatar piotrpio commented on August 23, 2024

Unfortunately this issue is not something that can be solved client-side.

When publishing a message to a stream, the client is essentially not aware whether there is an underlying stream or not. It simply publishes a standard NATS request (message with reply subject) on a stream's subject and waits for the response. If there is another non-jetstream subscription listening on this subject (and the stream does not exist), this will end with a timeout. The server is also not aware whether the request is jetstream specific or not, since this is a standard NATS message. To know for sure whether there is a stream with interest on the publish subject, we would have to send a separate JetStream request to get the streams, which is not something we want to do on each publish (or even after the timeout is hit).

My suggestion would be to not use the same subject for both stream and standard NATS subscription. If you want a separate subscription to just do the logging, I would suggest creating a simple ephemeral consumer with AckPolicy set to AckNone and possibly DeliverPolicy set to DeliverNewPolicy (you can use stream.OrderedConsumer() for simplicity).

from nats.go.

kung-foo avatar kung-foo commented on August 23, 2024

I kinda figured.
There is the ExpectedStreamHeader option which implies that you can communicate something about JetStream even though it is "just a NATS message".
I think the docs should indicate the limitations of the error response for this API. My reading of the existence of a "retry" option is that any error during publication will trigger a retry. However, it is only an ErrNoResponders error where a retry is attempted. And since that error is somewhat unreliable, it makes it hard to reason about what will and will not happen.

from nats.go.

piotrpio avatar piotrpio commented on August 23, 2024

Agreed, docs can be improved. ExpectedStreamHeader is there, but it's optional and is handled within the context of the stream itself, before sending ACK to the client. It is there to make sure that the subject you publish on belongs to the stream you expect. It will not be treated in a special way by the server if the stream for the given subject does not exist.

from nats.go.

jnmoyne avatar jnmoyne commented on August 23, 2024

There are 3 ways a JS publish can fail and you must catch and log them all:

  1. No responders
  2. Timeout
  3. Error returned by the server (e.g. some limit is hit).

The first 2 cases are equivalent from the client application's perspective: either wait a few seconds and try again or give up.

Will add something about this in the docs.

from nats.go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.