Skip to content

Commit

Permalink
fix: make nats consumer durable with cleanup after one week (nameserv…
Browse files Browse the repository at this point in the history
  • Loading branch information
linxside authored Mar 17, 2024
1 parent 4d938fb commit 824712b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/microservice/messaging/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ func (nb *natsBroker) CreatePersistentMessageReceiver(name, id, address, port, c
messageStartTime := time.Now().Add(-15 * time.Minute).Round(time.Minute)

cfg := jetstream.ConsumerConfig{
Name: name + id,
DeliverPolicy: jetstream.DeliverByStartTimePolicy,
OptStartTime: &messageStartTime,
AckPolicy: jetstream.AckNonePolicy,
Metadata: map[string]string{"id": id, "address": address, "port": port, "type": cType},
Name: name + id,
Durable: name + id,
InactiveThreshold: 8 * 24 * time.Hour,
DeliverPolicy: jetstream.DeliverByStartTimePolicy,
OptStartTime: &messageStartTime,
AckPolicy: jetstream.AckNonePolicy,
Metadata: map[string]string{"id": id, "address": address, "port": port, "type": cType},
}

consumer, err := stream.CreateOrUpdateConsumer(ctx, cfg)
Expand Down

0 comments on commit 824712b

Please sign in to comment.