Fix namespacing

This commit is contained in:
Neil Alexander 2022-01-07 16:46:49 +00:00
parent 8c20a7f7ce
commit 9e341501b2
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -74,14 +74,22 @@ func setupNATS(cfg *config.JetStream, nc *natsclient.Conn) (nats.JetStreamContex
logrus.WithError(err).Fatal("Unable to get stream info")
}
if info == nil {
stream.Subjects = []string{name}
// Define a default subject if not already specified.
if len(stream.Subjects) == 0 {
stream.Subjects = []string{name}
}
// If we're trying to keep everything in memory (e.g. unit tests)
// then overwrite the storage policy.
if cfg.InMemory {
stream.Storage = nats.MemoryStorage
}
if _, err = s.AddStream(stream); err != nil {
// Namespace the streams without modifying the original streams
// array, otherwise we end up with namespaces on namespaces.
namespaced := *stream
namespaced.Name = name
if _, err = s.AddStream(&namespaced); err != nil {
logrus.WithError(err).WithField("stream", name).Fatal("Unable to add stream")
}
}