process: Account.NamedEventConsumer binds the durable <node>_<module>_<suffix> beside EventConsumer's

Builds: design 47 H §743, H-A-90
This commit is contained in:
2026-11-20 03:31:31 +01:00
parent 7f3b712a1f
commit f1b828c6e5
3 changed files with 22 additions and 0 deletions
+1
View File
@@ -268,6 +268,7 @@ func TestModuleAccountNamesAndDialOptions(t *testing.T) {
{"template stream subject", a.BusSubject("events", "snapshot.taken.person"), "mesh.bus.mesh-delivery-teller.events.snapshot.taken.person"},
{"another module's stream subject", ModuleStreamSubject("mesh-delivery-checker", "check"), "mesh.stream.mesh-delivery-checker.event.check"},
{"durable consumer", a.EventConsumerName(), "n1_mesh-delivery-teller"},
{"named durable consumer (H-A-90)", a.namedEventConsumerName("main"), "n1_mesh-delivery-teller_main"},
} {
if c.got != c.want {
t.Errorf("%s: got %q, want %q", c.name, c.got, c.want)
+11
View File
@@ -65,6 +65,17 @@ func subTheHubBindsALateConsumerAndSaysItIsLive(t *testing.T) {
case <-ctx.Done():
t.Fatal("the consumer was made and the hub never said it is live")
}
// H-A-90: a durable named for a suffix is bound beside the module's own.
if _, err := js.CreateOrUpdateConsumer(ctx, process.EventsStream, jetstream.ConsumerConfig{Durable: cred.EventConsumerName() + "_main", AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
t.Fatal(err)
}
named, err := cred.NamedEventConsumer(ctx, js, process.EventsStream, "main")
if err != nil || named.CachedInfo().Name != cred.EventConsumerName()+"_main" {
t.Fatalf("the named consumer: %v, %v", named, err)
}
if _, err := cred.NamedEventConsumer(ctx, js, process.EventsStream, "other"); err == nil {
t.Fatal("a named consumer nobody made was bound")
}
hub.Stop()
}
+10
View File
@@ -93,6 +93,16 @@ func (a Account) EventConsumer(ctx context.Context, js jetstream.JetStream, stre
return js.Consumer(ctx, stream, a.EventConsumerName())
}
// NamedEventConsumer binds the module's durable consumer named for a suffix on stream: <node>_<module>_<suffix>, beside
// EventConsumer's <node>_<module> (design 47 H §743, H-A-90: the indexer's one durable per watched branch).
func (a Account) NamedEventConsumer(ctx context.Context, js jetstream.JetStream, stream, suffix string) (jetstream.Consumer, error) {
return js.Consumer(ctx, stream, a.namedEventConsumerName(suffix))
}
func (a Account) namedEventConsumerName(suffix string) string {
return a.EventConsumerName() + "_" + suffix
}
// HearEvents pulls from cons, handing each message to handle, and says every error the bus reports while
// hearing through logf ("hearing the bus: ..."). The caller stops the returned context.
func HearEvents(cons jetstream.Consumer, handle func(jetstream.Msg), logf func(string, ...any)) (jetstream.ConsumeContext, error) {