feat: implement cross-node event broadcasting with NATSEventBus

- Add UpdateVersionCache method to JetStreamEventStore for cache synchronization
- Add SubscribeToEventStored convenience helper to NATSEventBus
- Create integration tests for cross-node broadcasting scenarios
- Add example demonstrating NATSEventBus + JetStreamEventStore integration
- Tests verify:
  - Single-node broadcasting works
  - Multi-node event flow works
  - Version cache consistency across nodes
  - Namespace isolation maintained
  - EventStored subscription works correctly
This commit is contained in:
Claude Code
2026-05-17 13:46:50 +02:00
parent 6041479286
commit f46348ab07
4 changed files with 294 additions and 0 deletions

View File

@@ -558,5 +558,18 @@ func sanitizeSubject(s string) string {
return s
}
// UpdateVersionCache updates the version cache for a specific actor.
// This is used when receiving events from other nodes via NATS to keep
// the version cache consistent across cluster nodes.
func (jes *JetStreamEventStore) UpdateVersionCache(actorID string, version int64) {
jes.mu.Lock()
defer jes.mu.Unlock()
// Only update if the new version is greater than cached version
if currentVersion, ok := jes.versions[actorID]; !ok || version > currentVersion {
jes.versions[actorID] = version
}
}
// Compile-time check that JetStreamEventStore implements EventStoreWithErrors
var _ aether.EventStoreWithErrors = (*JetStreamEventStore)(nil)