feat: implement cross-node event broadcasting with NATSEventBus
All checks were successful
CI / build (pull_request) Successful in 20s
All checks were successful
CI / build (pull_request) Successful in 20s
- 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
This commit is contained in:
@@ -210,6 +210,26 @@ func (neb *NATSEventBus) Publish(namespaceID string, event *Event) {
|
||||
}
|
||||
}
|
||||
|
||||
// SubscribeToEventStored creates a subscription specifically for EventStored events.
|
||||
// This is a convenience method for the common pattern of listening to persisted events
|
||||
// to update version cache or trigger other actions.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// eventStoredCh := natsBus.SubscribeToEventStored("tenant-abc")
|
||||
// go func() {
|
||||
// for event := range eventStoredCh {
|
||||
// actorID := event.Data["actorId"].(string)
|
||||
// version := int64(event.Data["version"].(float64))
|
||||
// store.UpdateVersionCache(actorID, version)
|
||||
// }
|
||||
// }()
|
||||
func (neb *NATSEventBus) SubscribeToEventStored(namespacePattern string) <-chan *Event {
|
||||
return neb.SubscribeWithFilter(namespacePattern, &SubscriptionFilter{
|
||||
EventTypes: []string{EventTypeEventStored},
|
||||
})
|
||||
}
|
||||
|
||||
// Stop closes the NATS event bus and all subscriptions
|
||||
func (neb *NATSEventBus) Stop() {
|
||||
neb.mutex.Lock()
|
||||
|
||||
Reference in New Issue
Block a user