//https://eventstore.org/blog/20130306/getting-started-part-3-subscriptions/ //SubscribeToAllFrom(this IEventStoreConnection target, // Position? lastCheckpoint, // CatchUpSubscriptionSettings settings, // Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared, // Action<EventStoreCatchUpSubscription> liveProcessingStarted = null, // Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null, // UserCredentials userCredentials = null) private Action <EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared(Projection projection) => (_, e) => { // check system events and ignore them... if (e.OriginalEvent.EventType.StartsWith("$")) { return; } // find event type var eventType = EventTypeMapper.GetType(e.Event.EventType); if (eventType == null) { return; } // deserialize the event. var domainEvent = e.Deserialze(); //build your projection projection.Handle(domainEvent); //store current checkpoint checkpointStore.SetCheckpoint(e.OriginalPosition.Value, projection); Console.WriteLine($"{DateTime.UtcNow.Ticks}---{e.Event.EventStreamId}-{domainEvent} projected into {projection}-{e.OriginalPosition.Value}"); };
public static object Deserialze(this ResolvedEvent resolvedEvent) { var dataType = EventTypeMapper.GetType(resolvedEvent.Event.EventType); var jsonData = Encoding.UTF8.GetString(resolvedEvent.Event.Data); var data = JsonConvert.DeserializeObject(jsonData, dataType); return(data); }
public async Task <long> SaveSnapshotAsync <T>(Snapshot snapshot) where T : Aggregate { var stream = GetStreamName <T>(snapshot.AggregateId); var snapshotEvent = new EventData( snapshot.Id, EventTypeMapper.GetTypeName(snapshot.GetType()), EventSerializer.IsJsonSerializer, EventSerializer.Serialize(snapshot), null); var result = await eventStoreConnection.AppendToStreamAsync(stream, ExpectedVersion.Any, snapshotEvent); return(result.LogPosition.CommitPosition); }