Subscribe to Consumer without mentioning JetStream name #1769
Replies: 2 comments 2 replies
-
Firstly, I think you may be confusing some concepts - Stream and JetStream are not the same and I think when you're talking about JetStream name you actually mean stream name. JetStream is the NATS server data persistence layer, while Streams are the individual, named message stores within JetStream. Please correct me if you meant something else. It is not possible to get a consumer using just the consumer name (consumer is always bound to a specific stream and there is no way to bypass it). Using Are you using the legacy JetStream API (in In the new API, you have 2 ways of getting the consumer instance to start receiving messages from a stream (I'm skipping error handling in these examples):
js, _ := jetstream.New(nc)
stream, _ := js.Stream(ctx, "STREAM_NAME")
consumer, _ := stream.Consumer(ctx, "CONSUMER_NAME")
cc, _ := consumer.Consume(func(msg jetstream.Msg){})
js, _ := jetstream.New(nc)
consumer, _ := js.Consumer(ctx, "STREAM_NAME", "CONSUMER_NAME")
cc, _ := consumer.Consume(func(jetstream.Msg){}) |
Beta Was this translation helpful? Give feedback.
-
A stream and consumer is directly related to if you have many streams each can have a consumer called “C”. Names are not unique per jetstream only per stream. How would it know which one you mean without the stream name? |
Beta Was this translation helpful? Give feedback.
-
Hello,
When we use Nats API to subscribe to some events from Jetstream fist of all we have to specify which Consumer we would like to use, but current SDK APIs require to mention JetStream name in order to identify consumer, as Consumer Id is based on pair of Consumer name + JetStream name.
I find this API a bit redundant and this seems to be the only place where in the code I have to specify Jetstream name, as publish does not require JS, but only subscribe.
I wonder if some unique identifier for Consumer can be created, so we can subscribe only based on it, without mentioning JS name. This enable us to make JS as abstraction so code can be written without specifing stream.
something like:
instead of
Please share your thoughts :)
Beta Was this translation helpful? Give feedback.
All reactions