Example #1
0
        public EventReader(IEventStoreReader reader, PersistedEventFactory factory)
        {
            Argument.Requires(reader != null, nameof(reader));
            Argument.Requires(factory != null, nameof(factory));

            _workerProps = Props.Create <ReadWorker>(reader, factory);
            Receive <ReadRequest>(r => HandleRequest(r));
        }
Example #2
0
        void InitializeServices(EvenStartInfo startInfo)
        {
            var serializer   = startInfo.Serializer;
            var store        = startInfo.Store;
            var options      = startInfo.Options;
            var registry     = new EventRegistry();
            var eventFactory = new PersistedEventFactory(registry, serializer);

            foreach (var kvp in startInfo.EventTypes)
            {
                registry.Register(kvp.Key, kvp.Value);
            }

            // initialize reader
            var readerProps = EventStoreReader.CreateProps(store, eventFactory, options);

            _reader = Context.ActorOf(readerProps, "reader");

            // initialize dispatcher
            var dispatcherProps = EventDispatcher.CreateProps(_reader, options);

            _dispatcher = Context.ActorOf(dispatcherProps, "dispatcher");

            // initialize writer
            var writerProps = EventStoreWriter.CreateProps(store, serializer, _dispatcher, options);

            _writer = Context.ActorOf(writerProps, "writer");

            // initialize event processor supervisor
            var eventProcessorsProps = EventProcessorSupervisor.CreateProps(options);

            _eventProcessors = Context.ActorOf(eventProcessorsProps, "eventprocessors");

            // initialize projection streams supervisor
            var projectionStreamsProps = ProjectionStreamSupervisor.CreateProps(_reader, _writer, options);

            _projectionStreams = Context.ActorOf(projectionStreamsProps, "projectionstreams");

            // initialize projections supervisor
            var projectionProps = ProjectionSupervisor.CreateProps(_projectionStreams, options);

            _projections = Context.ActorOf(projectionProps, "projections");

            // initialize command processors supervisor
            var commandProcessorsProps = CommandProcessorSupervisor.CreateProps(_writer, options);

            _commandProcessors = Context.ActorOf(commandProcessorsProps, "commandprocessors");

            // initialize aggregates
            var aggregatesProps = AggregateSupervisor.CreateProps(_reader, _writer, options);

            _aggregates = Context.ActorOf(aggregatesProps, "aggregates");
        }
Example #3
0
        protected async Task WriteEvents(PersistenceRequest request)
        {
            var events = request.Events;

            // serialize the events into raw events
            var rawEvents = UnpersistedRawEvent.FromUnpersistedEvents(events, _serializer);

            // writes all events to the store
            await _writer.WriteStreamAsync(request.Stream, request.ExpectedStreamSequence, rawEvents);

            // publishes the events in the order they were sent
            for (int i = 0, len = events.Count; i < len; i++)
            {
                var e              = events[i];
                var re             = rawEvents[i];
                var persistedEvent = PersistedEventFactory.FromUnpersistedEvent(re.GlobalSequence, e);

                // publish to the event stream
                _dispatcher.Tell(persistedEvent);
            }
        }
Example #4
0
        async Task Write(IReadOnlyList <BufferEntry> bufferEntries)
        {
            // creates a list of "Event + Sender" entries
            var entries = bufferEntries.SelectMany(entry => entry.Request.Events.Select(@event => new { Event = @event, Sender = entry.Sender })).ToList();

            // serialize the events into raw events
            var rawEvents = UnpersistedRawEvent.FromUnpersistedEvents(entries.Select(e => e.Event), _serializer);

            // writes to the store
            await _writer.WriteAsync(rawEvents);

            // sends the events to the dispatcher
            for (int i = 0, len = entries.Count; i < len; i++)
            {
                var sender = entries[i].Sender;
                var e      = entries[i].Event;
                var re     = rawEvents[i];

                var persistedEvent = PersistedEventFactory.FromUnpersistedEvent(re.GlobalSequence, e);

                _dispatcher.Tell(persistedEvent);
            }
        }