nats.go icon indicating copy to clipboard operation
nats.go copied to clipboard

JetStreamContext ConsumerInfo and AddConsumer allow user to pass options but ignore them

Open tvojacek opened this issue 2 years ago • 2 comments

Defect

Signature of ConsumerInfo and AddConsumer allow pass JSOpt but ignore most of them only context or timeout is used. https://github.com/nats-io/nats.go/blob/543e628f4bafe989ce2ba548af09e2067c67ea69/jsm.go#L439 https://github.com/nats-io/nats.go/blob/543e628f4bafe989ce2ba548af09e2067c67ea69/jsm.go#L446 Rest of options like domain is ignored.

Versions of nats.go and the nats-server if one was involved:

nats.go 1.16 and 1.17

OS/Container environment:

N/A

Steps or code to reproduce the issue:

create jetstream my_stream_on_domain on domain my_domain and consumer "any_consumer_name" call:

	consumer, err := js.ConsumerInfo("my_stream_on_domain", "any_consumer_name", nats.Domain("my_domain"))
	if err != nil {
                if errors.Is(err, nats.ErrStreamNotFound) {
                        t.fail()
                 }
	}

Expected result:

got consumer info and err is nil

Actual result:

got error nats.ErrStreamNotFound

tvojacek avatar Oct 11 '22 16:10 tvojacek

The C client does the right thing there, by always using the default JS context or the option provided by individual calls. It looks like the Go client is using js.apiSubj() that only uses whatever is defined in the context, not in individual calls options.

kozlovic avatar Oct 11 '22 18:10 kozlovic

It is actually a bit problematic right now, as you can pass any JSOpt to any of the methods of JetStreamManager, even if it does not make much sense (like e.g. configuring StreamPurgeRequest). I am working on a solution which would restrict using some options only to particular methods, but some of those options (like Domain() or APIPrefix()) seem to be good candidates to use in many methods, not just when creating JetStreamContext (like the C client does).

piotrpio avatar Oct 12 '22 16:10 piotrpio