Skip to content

Commit 03122ba

Browse files
committed
Remove EventStoreConfig in favor of nats.StreamConfig
This was motivated by a constraint on NGS to require max bytes being set on the stream. Until there is good reason to create a custom config type, this will remain. Signed-off-by: Byron Ruth <[email protected]>
1 parent fa5a980 commit 03122ba

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

eventstore.go

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,6 @@ type natsStoredMsg struct {
136136
Sequence uint64 `json:"seq"`
137137
}
138138

139-
// EventStoreConfig is a subset of the nats.StreamConfig for the purpose of creating
140-
// purpose-built streams for an event store.
141-
type EventStoreConfig struct {
142-
// Description associated with the event store.
143-
Description string
144-
// Subjects to associated with the stream. If not specified, it will default to
145-
// the name plus the variadic wildcard, e.g. "orders.>"
146-
Subjects []string
147-
// Storage for the stream.
148-
Storage nats.StorageType
149-
// Replicas of the stream.
150-
Replicas int
151-
// Placement of the stream replicas.
152-
Placement *nats.Placement
153-
}
154-
155139
// EventStore provides event store semantics over a NATS stream.
156140
type EventStore struct {
157141
name string
@@ -410,41 +394,27 @@ func (s *EventStore) Evolve(ctx context.Context, subject string, model Evolver,
410394

411395
// Create creates the event store given the configuration. The stream
412396
// name is the name of the store and the subjects default to "{name}}.>".
413-
func (s *EventStore) Create(config *EventStoreConfig) error {
397+
func (s *EventStore) Create(config *nats.StreamConfig) error {
414398
if config == nil {
415-
config = &EventStoreConfig{}
399+
config = &nats.StreamConfig{}
416400
}
401+
config.Name = s.name
417402

418-
subjects := config.Subjects
419-
if len(subjects) == 0 {
420-
subjects = []string{fmt.Sprintf("%s.>", s.name)}
403+
if len(config.Subjects) == 0 {
404+
config.Subjects = []string{fmt.Sprintf("%s.>", s.name)}
421405
}
422406

423-
_, err := s.rt.js.AddStream(&nats.StreamConfig{
424-
Name: s.name,
425-
Description: config.Description,
426-
Subjects: subjects,
427-
Storage: config.Storage,
428-
Replicas: config.Replicas,
429-
Placement: config.Placement,
430-
DenyDelete: true,
431-
DenyPurge: true,
432-
})
407+
_, err := s.rt.js.AddStream(config)
433408
return err
434409
}
435410

436411
// Update updates the event store configuration.
437-
func (s *EventStore) Update(config *EventStoreConfig) error {
438-
_, err := s.rt.js.UpdateStream(&nats.StreamConfig{
439-
Name: s.name,
440-
Description: config.Description,
441-
Subjects: config.Subjects,
442-
Storage: config.Storage,
443-
Replicas: config.Replicas,
444-
Placement: config.Placement,
445-
DenyDelete: true,
446-
DenyPurge: true,
447-
})
412+
func (s *EventStore) Update(config *nats.StreamConfig) error {
413+
if config == nil {
414+
config = &nats.StreamConfig{}
415+
}
416+
config.Name = s.name
417+
_, err := s.rt.js.UpdateStream(config)
448418
return err
449419
}
450420

eventstore_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestEventStoreNoRegistry(t *testing.T) {
4646
is.NoErr(err)
4747

4848
es := r.EventStore("orders")
49-
err = es.Create(&EventStoreConfig{
49+
err = es.Create(&nats.StreamConfig{
5050
Storage: nats.MemoryStorage,
5151
})
5252
is.NoErr(err)
@@ -239,7 +239,7 @@ func TestEventStoreWithRegistry(t *testing.T) {
239239

240240
// Recreate the store for each test.
241241
_ = es.Delete()
242-
err := es.Create(&EventStoreConfig{
242+
err := es.Create(&nats.StreamConfig{
243243
Storage: nats.MemoryStorage,
244244
})
245245
is.NoErr(err)

0 commit comments

Comments
 (0)