Exemple #1
0
        //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)
        => async(_, e) =>
        {
            // check system events and ignore them...
            if (e.OriginalEvent.EventType.StartsWith("$"))
            {
                return;
            }

            // find event type
            var eventType = eventTypeMapper.GetEventType(e.Event.EventType);

            if (eventType == null)
            {
                return;
            }
            // deserialize the event.
            var domainEvent = serializer.Deserialize(e.Event.Data, eventType);

            //build your projection
            await projection.Handle(domainEvent);

            //store current checkpoint
            checkpointStore.SetCheckpoint(e.OriginalPosition.Value, projection);

            Console.WriteLine($"{domainEvent} projected into {projection}");
        };
Exemple #2
0
        Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(Projection projection)
        => (_, e) =>
        {
            // always double check if it is a system event ;)
            if (e.OriginalEvent.EventType.StartsWith("$"))
            {
                return;
            }

            // get the configured clr type name for deserializing the event
            if (!_typeMapper.TryGetType(e.Event.EventType, out var eventType))
            {
                Log.Debug("Failed to find clr type for {eventType}. Skipping...", e.Event.EventType);
            }
            else
            {
                // deserialize event
                var domainEvent = _serializer.Deserialize(e.Event.Data, eventType);

                // try to execute the projection
                if (projection.CanHandle(domainEvent))
                {
                    projection.Handle(domainEvent).GetAwaiter().GetResult();
                    Log.Debug("{projection} handled {event}", projection, domainEvent);
                }
            }

            // store the current checkpoint
            _checkpointStore.SetCheckpoint(e.OriginalPosition, projection).GetAwaiter().GetResult();
        };
Exemple #3
0
        private Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(Projection projection) =>
        async(_, e) =>
        {
            // always double check if it is a system event ;)
            if (e.OriginalEvent.EventType.StartsWith("$"))
            {
                return;
            }

            // get the configured clr type name for deserializing the event
            var eventType = _typeMapper.GetType(e.Event.EventType);

            // try to execute the projection
            await projection.Handle(_serializer.Deserialize(e.Event.Data, eventType));

            // store the current checkpoint
            await _checkpointStore.SetCheckpoint(e.OriginalPosition, projection);
        };