Beispiel #1
0
func RegisterIntegrationEventHandlers(eventDispatcher *cqrs.VersionedEventDispatchManager, integrationEventsLog cqrs.VersionedEventPublicationLogger, readModel *ReadModelAccounts, usersModel *UsersModel) {
	eventDispatcher.RegisterGlobalHandler(func(event cqrs.VersionedEvent) error {
		integrationEventsLog.SaveIntegrationEvent(event)
		readModel.UpdateViewModel([]cqrs.VersionedEvent{event})
		usersModel.UpdateViewModel([]cqrs.VersionedEvent{event})
		return nil
	})
}
Beispiel #2
0
func (model *ReadModelAccounts) LoadAccounts(persistance cqrs.VersionedEventPublicationLogger) {
	readBytes, error := ioutil.ReadFile("/tmp/accounts.json")

	if !os.IsNotExist(error) {
		log.Println("Loading accounts from disk")
		json.Unmarshal(readBytes, &model.Accounts)
	} else {
		log.Println("Replaying events from repository")
		events, error := persistance.AllIntegrationEventsEverPublished()
		if error == nil {
			model.UpdateViewModel(events)
		}
	}
}