Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsm: Replace listers with receive only channels #659

Closed
wants to merge 2 commits into from
Closed

Conversation

wallyqs
Copy link
Member

@wallyqs wallyqs commented Feb 11, 2021

This adds the following two APIs to JSM which can be used instead of the listers.

type JetStreamManager interface {
	// StreamsInfo can be used to retrieve a list of StreamInfo objects.
	StreamsInfo(ctx context.Context) <-chan *StreamInfo

	// ConsumersInfo is used to retrieve a list of ConsumerInfo objects.
	ConsumersInfo(ctx context.Context, stream string) <-chan *ConsumerInfo
}

func (js *js) StreamsInfo() <-chan *StreamInfo {
ach := make(chan *StreamInfo)
sl := &streamLister{js: js}
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like it should have timeouts and a way to cancel it etc no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, we could make it take options like, nats.MaxWait() and nats.Context() as I did with AckSync

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding options for both timeout and context (wallyqs@265ef17) but now thinking that might be simpler if only support context.Context instead for this case, so change to something like:

StreamsInfo(ctx context.Context) <-chan *StreamInfo
ConsumersInfo(ctx context.Context, stream string) <-chan *ConsumerInfo

jsm.go Outdated Show resolved Hide resolved
test/js_test.go Outdated
t.Errorf("Unexpected error: %v", err)
var i int
expected := "foo"
for stream := range js.StreamsInfo() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way this flows imo.

jsm.go Outdated
@@ -24,41 +24,41 @@ import (

// JetStreamManager is the public interface for managing JetStream streams & consumers.
type JetStreamManager interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi - Java also has an accessor to get stream names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, that API is not exposed in the JetStreamManager interface actually. Maybe we should add it too?

GetStreamBySubject(subj string) (*StreamInfo, error)

https://github.com/nats-io/nats.go/blob/master/js.go#L655-L662

@coveralls
Copy link

coveralls commented Feb 22, 2021

Coverage Status

Coverage decreased (-0.5%) to 87.019% when pulling 9cd671b on jsm-listers into 3678d91 on master.

jsm.go Show resolved Hide resolved
jsm.go Outdated Show resolved Hide resolved
@variadico variadico force-pushed the jsm-listers branch 4 times, most recently from d008667 to ee948d9 Compare February 25, 2021 00:15
@wallyqs wallyqs changed the title js: Replace JetStreamManager listers with receive only channels jsm: Replace listers with receive only channels Feb 25, 2021
@wallyqs
Copy link
Member Author

wallyqs commented Mar 4, 2021

Need to have branch ready that replaces the lister APIs used by the server before merging.

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
@variadico
Copy link
Contributor

Ready to update the server side after this PR merges.
nats-io/nats-server#1968

var o jsmOpts
if len(opts) > 0 {
for _, opt := range opts {
if err := opt.configureJSManager(&o); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a helper/DRY for some of these?

@wallyqs
Copy link
Member Author

wallyqs commented Mar 10, 2021

Closing in favor of this one #674

@wallyqs wallyqs closed this Mar 10, 2021
@wallyqs wallyqs deleted the jsm-listers branch March 10, 2021 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants