Skip to content

Commit

Permalink
Merge pull request #319 from sysbot/bao/dontcreateifexist
Browse files Browse the repository at this point in the history
don't recreate stream if it already exist
  • Loading branch information
maxekman committed Jun 7, 2021
2 parents c1fdafd + 0fbefd6 commit f3b6276
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions eventbus/jetstream/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ func NewEventBus(url, appID string, options ...Option) (*EventBus, error) {
return nil, fmt.Errorf("could not create Jetstream context: %w", err)
}

if b.stream, err = b.js.StreamInfo(b.streamName); err == nil {
return b, nil
}

// Create the stream, which stores messages received on the subject.
subjects := b.streamName + ".*.*"
cfg := &nats.StreamConfig{
Name: b.streamName,
Subjects: []string{subjects},
Storage: nats.FileStorage,
}

if b.stream, err = b.js.AddStream(cfg); err != nil {
return nil, fmt.Errorf("could not create Jetstream stream: %w", err)
}
Expand Down

0 comments on commit f3b6276

Please sign in to comment.