diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved.go index 71587421..cde7d759 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved.go @@ -7,6 +7,7 @@ import ( "fmt" "slices" "sync" + "time" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" @@ -105,15 +106,26 @@ func bindBranch(js jetstream.JetStream, cred process.Account, logf func(string, // branchConsumerConfig is the indexer's durable of one watched branch as the mesh gives a module's seat-event consumer // (mesh-sdk's SeatEventConsumerConfig), named __ as NamedEventConsumer binds it, filtered to the -// branch's source-moved and delivering one message at a time (design 47 H §743, H-A-90, H-A-134). +// branch's source-moved and delivering one message at a time, with the ack wait of 30 s, the at most 5 deliveries and the +// start from now the grants part gives a module's consumer on a seat event's stream kept by age (mesh-grants buscompose +// heardConsumer): the branch's current source revision is read at the start through the gate's source (H-A-129, H-A-130), so +// its past source-moved are never taken in again (design 47 H §743, H-A-90, H-A-134). func branchConsumerConfig(cred process.Account, branch string) jetstream.ConsumerConfig { esc := keys.EscapeName(branch) cfg := cred.SeatEventConsumerConfig([]string{meshdelivery.SubjectSourceMoved(esc, "*")}, false) cfg.Durable = cred.EventConsumerName() + "_" + esc cfg.MaxAckPending = 1 + cfg.AckWait, cfg.MaxDeliver = branchAckWait, branchMaxDeliver + cfg.DeliverPolicy = jetstream.DeliverNewPolicy return cfg } +// The ack wait and the deliveries of a branch's durable, as the grants part gives a module's consumers (H-A-134, H-A-133). +const ( + branchAckWait = 30 * time.Second + branchMaxDeliver = 5 +) + // refresh binds the consumer of every watched branch not bound yet: at the start and on each registration-changed. A consumer // not there yet is said and bound at the next registration-changed or start. The start's refresh reads every watched branch's // source revision, a later one each branch whose consumer could not be bound (H-A-129), after the binds. diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go index 9b9fcfa0..9b3feb36 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go @@ -8,6 +8,7 @@ import ( "slices" "strings" "testing" + "time" "github.com/nats-io/nats.go/jetstream" @@ -226,6 +227,7 @@ func TestABranchDurableNotThereIsMadeAndHeard(t *testing.T) { } want := cred.SeatEventConsumerConfig([]string{meshdelivery.SubjectSourceMoved(keys.EscapeName("main"), "*")}, false) want.Durable, want.MaxAckPending = name, 1 + want.AckWait, want.MaxDeliver, want.DeliverPolicy = 30*time.Second, 5, jetstream.DeliverNewPolicy if len(js.made) != 1 || !reflect.DeepEqual(js.made[0], want) { t.Fatalf("made %+v, want once %+v", js.made, want) }