Difference between SubscribeAsync vs ConsumeAsync in jetstream context #669
-
Since subscribe async is a concept of core-nats, i was under the assumption that subscribe async would not persist messages to stream when used in context of jetstream. But i find out that SubscribeAsync is still persisitning data to stream. Question 1) What is use case of subscribeAsync & consumeAsync Question 2) Is there no way we can do a request-reply format in jetstream without persisiting to stream. Requesting some assistance from community!.. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
you can't tell publish calls to persist a message. whether a message will be persisted or not is controlled by the stream configuration where you can list a set of subjects often with wildcards. when you subscribe you only get the new messages published from that point in time forward. when you consume subjects set up to be persisted by a stream you can retrieve the persisted messages which might've been sent before the time of consumption. for request reply you don't need jetstream anyway. just make sure to use subjects that are not configured by any stream to be persisted. hope it helps PS anyone please feel free to jump in for a different perspective and possibly a better explanation. PPS see also https://nats-io.github.io/nats.net/documentation/jetstream/intro.html |
Beta Was this translation helpful? Give feedback.
you'd need to use different subjects e.g.
orders.>
could be ones you want to persist and set up as part of aORDERS
stream andevents.>
could be for just plain NATS core messages and not configured in any stream.it's like layers. JetStream is built on top of NATS Core and you can observe messages being published by subscribing to the same subjects as streams configured to persist. but unless you use a consumer to get those messages from a stream they won't be taken out of a work queue stream for example.