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

CreateStreamIfAbsent or CreateOrUpdateStream api #1430

Closed
tamalsaha opened this issue Oct 4, 2023 · 1 comment
Closed

CreateStreamIfAbsent or CreateOrUpdateStream api #1430

tamalsaha opened this issue Oct 4, 2023 · 1 comment
Labels
proposal Enhancement idea or proposal

Comments

@tamalsaha
Copy link

What motivated this proposal?

Please add an api that will create a Stream is not exists and return it if exists. Hence the CreateStreamIfAbsent api. This api is needed to auto create the stream from my application. It was surprising to not have this api.

CreateOrUpdateStream might nice to keeping in sync with the CreateOrUpdateConsumer api. Though, I have not felt th need for this api.

What is the proposed change?

Something like this is what I am doing.

func ensureStream(stream string, jsOpts ...jetstream.JetStreamOpt) (jetstream.Stream, error) {
	js, err := jetstream.New(mgr.nc, jsOpts...)
	if err != nil {
		return nil, err
	}

	s, err := js.Stream(context.TODO(), stream)
	if errors.Is(err, jetstream.ErrStreamNotFound) {
		s, err = js.CreateStream(context.TODO(), jetstream.StreamConfig{
			Name:     stream,
			Subjects: []string{stream + ".*"},
		})
	}
	return s, err
}

Who benefits from this change?

No response

What alternatives have you evaluated?

No response

@tamalsaha tamalsaha added the proposal Enhancement idea or proposal label Oct 4, 2023
@piotrpio
Copy link
Collaborator

piotrpio commented Oct 7, 2023

Hey @tamalsaha, thanks for submitting the issue. CreateOrUpdateStream function was merged a momento ago: #1395

It will be included in the next release.

@piotrpio piotrpio closed this as completed Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

2 participants