예제 #1
0
        protected override void Create()
        {
            base.Create();
            var db = this.TfDb;

            _coreInputBus = new InMemoryBus("bus");
            _coreQueue    = new QueuedHandler(_coreInputBus, "ProjectionCoreQueue");

            _readerInputBus = new InMemoryBus("Reader Input");

            _projectionNode = new ProjectionWorkerNode(db, _coreQueue, Node.HttpService);
            _projectionNode.SetupMessaging(_coreInputBus, _readerInputBus);

            _forwarder = new RequestResponseQueueForwarder(inputQueue: _coreQueue, externalRequestQueue: Node.MainQueue);
            // forwarded messages
            _projectionNode.CoreOutput.Subscribe <ClientMessage.ReadEvent>(_forwarder);
            _projectionNode.CoreOutput.Subscribe <ClientMessage.ReadEventsBackwards>(_forwarder);
            _projectionNode.CoreOutput.Subscribe <ClientMessage.ReadEventsForward>(_forwarder);
            _projectionNode.CoreOutput.Subscribe <ClientMessage.ReadEventsFromTF>(_forwarder);
            _projectionNode.CoreOutput.Subscribe <ClientMessage.WriteEvents>(_forwarder);
            _coreInputBus.Subscribe(new UnwrapEnvelopeHandler());

            Node.Bus.Subscribe(Forwarder.Create <SystemMessage.BecomeShuttingDown>(_coreQueue));
            Node.Bus.Subscribe(Forwarder.Create <SystemMessage.SystemInit>(_coreQueue));
            Node.Bus.Subscribe(Forwarder.Create <SystemMessage.SystemStart>(_coreQueue));

            _projectionNode.CoreOutput.Subscribe(Node.TimerService);
            _coreInputBus.Subscribe <SystemMessage.SystemStart>(this);
        }
예제 #2
0
        private static void SubscribeOutputBus(
            StandardComponents standardComponents,
            ProjectionsStandardComponents projectionsStandardComponents,
            RequestResponseQueueForwarder forwarder)
        {
            var managerOutput = projectionsStandardComponents.MasterOutputBus;

            managerOutput.Subscribe <ClientMessage.ReadEvent>(forwarder);
            managerOutput.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
            managerOutput.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
            managerOutput.Subscribe <ClientMessage.WriteEvents>(forwarder);
            managerOutput.Subscribe <ClientMessage.DeleteStream>(forwarder);
            managerOutput.Subscribe(
                Forwarder.Create <ProjectionManagementMessage.RequestSystemProjections>(standardComponents.MainQueue));
            managerOutput.Subscribe(Forwarder.Create <Message>(projectionsStandardComponents.MasterInputQueue));

            managerOutput.Subscribe <TimerMessage.Schedule>(standardComponents.TimerService);
            managerOutput.Subscribe(Forwarder.Create <AwakeServiceMessage.SubscribeAwake>(standardComponents.MainQueue));
            managerOutput.Subscribe(
                Forwarder.Create <AwakeServiceMessage.UnsubscribeAwake>(standardComponents.MainQueue));

            // self forward all
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <SystemMessage.StateChangeMessage>(projectionsStandardComponents.MasterInputQueue));
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <SystemMessage.SystemReady>(projectionsStandardComponents.MasterInputQueue));
            projectionsStandardComponents.MasterMainBus.Subscribe(new UnwrapEnvelopeHandler());
        }
예제 #3
0
        public ProjectionWorkerNode(TFChunkDb db, IPublisher coreQueue, HttpService httpService)
        {
            Ensure.NotNull(db, "db");
            Ensure.NotNull(coreQueue, "coreQueue");

            _coreQueue = coreQueue;
            CoreOutput = new InMemoryBus("Core Output");

            _projectionCoreService = new ProjectionCoreService(CoreOutput, 10, db.Config.WriterCheckpoint);
            CoreOutput.Subscribe(Forwarder.Create <Message>(_coreQueue)); // forward all

            _projectionManager = new ProjectionManager(CoreOutput, db.Config.WriterCheckpoint);

            httpService.SetupController(new ProjectionsController(_coreQueue));
        }
예제 #4
0
        private static void SubscribeOutputBus(
            StandardComponents standardComponents,
            ProjectionsStandardComponents projectionsStandardComponents,
            RequestResponseQueueForwarder forwarder,
            IODispatcher ioDispatcher)
        {
            var managerOutput = projectionsStandardComponents.LeaderOutputBus;

            managerOutput.Subscribe <ClientMessage.ReadEvent>(forwarder);
            managerOutput.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
            managerOutput.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
            managerOutput.Subscribe <ClientMessage.WriteEvents>(forwarder);
            managerOutput.Subscribe <ClientMessage.DeleteStream>(forwarder);
            managerOutput.Subscribe(Forwarder.Create <Message>(projectionsStandardComponents.LeaderInputQueue));
            managerOutput.Subscribe <ClientMessage.NotHandled>(ioDispatcher);

            managerOutput.Subscribe <TimerMessage.Schedule>(standardComponents.TimerService);
            managerOutput.Subscribe(Forwarder.Create <AwakeServiceMessage.SubscribeAwake>(standardComponents.MainQueue));
            managerOutput.Subscribe(
                Forwarder.Create <AwakeServiceMessage.UnsubscribeAwake>(standardComponents.MainQueue));
            managerOutput.Subscribe <SystemMessage.SubSystemInitialized>(forwarder);

            // self forward all
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <SystemMessage.StateChangeMessage>(projectionsStandardComponents.LeaderInputQueue));
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <SystemMessage.SystemCoreReady>(projectionsStandardComponents.LeaderInputQueue));
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <SystemMessage.EpochWritten>(projectionsStandardComponents.LeaderInputQueue));
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <ProjectionCoreServiceMessage.SubComponentStarted>(projectionsStandardComponents
                                                                                    .LeaderInputQueue));
            standardComponents.MainBus.Subscribe(
                Forwarder.Create <ProjectionCoreServiceMessage.SubComponentStopped>(projectionsStandardComponents
                                                                                    .LeaderInputQueue));
            projectionsStandardComponents.LeaderMainBus.Subscribe(new UnwrapEnvelopeHandler());
        }
        private void SetUpCoreServices(
            Guid workerId,
            IBus bus,
            IPublisher inputQueue,
            InMemoryBus output_,
            ISingletonTimeoutScheduler timeoutScheduler)
        {
            var         output           = (output_ ?? inputQueue);
            ICheckpoint writerCheckpoint = new InMemoryCheckpoint(1000);
            var         readerService    = new EventReaderCoreService(
                output,
                _ioDispatcher,
                10,
                writerCheckpoint,
                runHeadingReader: true, faultOutOfOrderProjections: true);

            _subscriptionDispatcher = new ReaderSubscriptionDispatcher(inputQueue);

            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CheckpointSuggested>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.CommittedEventReceived>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.EofReached>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionEofReached>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.PartitionDeleted>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ProgressChanged>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.SubscriptionStarted>());
            bus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.NotAuthorized>());
            bus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.ReaderAssignedReader>());

            var ioDispatcher = new IODispatcher(output, new PublishEnvelope(inputQueue), true);
//            var coreServiceCommandReader = new ProjectionCoreServiceCommandReader(
//                output,
//                ioDispatcher,
//                workerId.ToString("N"));

            var coreService = new ProjectionCoreService(
                workerId,
                inputQueue,
                output,
                _subscriptionDispatcher,
                _timeProvider,
                ioDispatcher,
                timeoutScheduler);

            bus.Subscribe <CoreProjectionManagementMessage.CreateAndPrepare>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.CreatePrepared>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Dispose>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Start>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.LoadStopped>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Stop>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.Kill>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.GetState>(coreService);
            bus.Subscribe <CoreProjectionManagementMessage.GetResult>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.CheckpointCompleted>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.CheckpointLoaded>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.PrerecordedEventsLoaded>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.RestartRequested>(coreService);
            bus.Subscribe <CoreProjectionProcessingMessage.Failed>(coreService);
            bus.Subscribe <ClientMessage.ReadStreamEventsForwardCompleted>(ioDispatcher.ForwardReader);
            bus.Subscribe <ClientMessage.ReadStreamEventsBackwardCompleted>(ioDispatcher.BackwardReader);
            bus.Subscribe <ClientMessage.WriteEventsCompleted>(ioDispatcher.Writer);
            bus.Subscribe <ClientMessage.DeleteStreamCompleted>(ioDispatcher.StreamDeleter);
            bus.Subscribe <IODispatcherDelayedMessage>(ioDispatcher.Awaker);
            bus.Subscribe <IODispatcherDelayedMessage>(ioDispatcher);
            bus.Subscribe <ProjectionCoreServiceMessage.StartCore>(coreService);
            bus.Subscribe <ProjectionCoreServiceMessage.StopCore>(coreService);
            bus.Subscribe <ReaderCoreServiceMessage.StartReader>(readerService);
            bus.Subscribe <ReaderCoreServiceMessage.StopReader>(readerService);
            bus.Subscribe <ProjectionCoreServiceMessage.CoreTick>(coreService);
            bus.Subscribe <ReaderSubscriptionMessage.CommittedEventDistributed>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderEof>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderPartitionEof>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderPartitionDeleted>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderNotAuthorized>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderIdle>(readerService);
            bus.Subscribe <ReaderSubscriptionMessage.EventReaderStarting>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Pause>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Resume>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Subscribe>(readerService);
            bus.Subscribe <ReaderSubscriptionManagement.Unsubscribe>(readerService);

            if (output_ != null)
            {
                bus.Subscribe(new UnwrapEnvelopeHandler());
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.StateReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.ResultReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.StatisticsReport>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Started>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Stopped>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Faulted>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <CoreProjectionStatusMessage.Prepared>(GetInputQueue()));
                output_.Subscribe(
                    Forwarder.Create <ProjectionManagementMessage.Command.ControlMessage>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <AwakeServiceMessage.SubscribeAwake>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <AwakeServiceMessage.UnsubscribeAwake>(GetInputQueue()));
                output_.Subscribe(Forwarder.Create <Message>(inputQueue));                // forward all

                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: inputQueue,
                    externalRequestQueue: GetInputQueue());
                // forwarded messages
                output_.Subscribe <ClientMessage.ReadEvent>(forwarder);
                output_.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                output_.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                output_.Subscribe <ClientMessage.ReadAllEventsForward>(forwarder);
                output_.Subscribe <ClientMessage.WriteEvents>(forwarder);
            }
        }
        public static Dictionary <Guid, IQueuedHandler> CreateCoreWorkers(
            StandardComponents standardComponents,
            ProjectionsStandardComponents projectionsStandardComponents)
        {
            var coreTimeoutSchedulers =
                CreateTimeoutSchedulers(projectionsStandardComponents.ProjectionWorkerThreadCount);

            var coreQueues = new Dictionary <Guid, IQueuedHandler>();

            while (coreQueues.Count < projectionsStandardComponents.ProjectionWorkerThreadCount)
            {
                var coreInputBus = new InMemoryBus("bus");
                var coreQueue    = QueuedHandler.CreateQueuedHandler(coreInputBus,
                                                                     "Projection Core #" + coreQueues.Count,
                                                                     groupName: "Projection Core");
                var workerId       = Guid.NewGuid();
                var projectionNode = new ProjectionWorkerNode(
                    workerId,
                    standardComponents.Db,
                    coreQueue,
                    standardComponents.TimeProvider,
                    coreTimeoutSchedulers[coreQueues.Count],
                    projectionsStandardComponents.RunProjections);
                projectionNode.SetupMessaging(coreInputBus);

                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: coreQueue,
                    externalRequestQueue: standardComponents.MainQueue);
                // forwarded messages
                var coreOutput = projectionNode.CoreOutput;
                coreOutput.Subscribe <ClientMessage.ReadEvent>(forwarder);
                coreOutput.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                coreOutput.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                coreOutput.Subscribe <ClientMessage.ReadAllEventsForward>(forwarder);
                coreOutput.Subscribe <ClientMessage.WriteEvents>(forwarder);
                coreOutput.Subscribe <ClientMessage.DeleteStream>(forwarder);


                if (projectionsStandardComponents.RunProjections >= ProjectionType.System)
                {
                    var slaveProjectionResponseWriter = projectionNode.SlaveProjectionResponseWriter;
                    coreOutput.Subscribe <PartitionMeasuredOutput>(slaveProjectionResponseWriter);
                    coreOutput.Subscribe <PartitionProcessingProgressOutput>(slaveProjectionResponseWriter);
                    coreOutput.Subscribe <PartitionProcessingResultOutput>(slaveProjectionResponseWriter);
                    coreOutput.Subscribe <ReaderSubscriptionManagement.SpoolStreamReading>(slaveProjectionResponseWriter);


                    coreOutput.Subscribe(
                        Forwarder.Create <AwakeServiceMessage.SubscribeAwake>(standardComponents.MainQueue));
                    coreOutput.Subscribe(
                        Forwarder.Create <AwakeServiceMessage.UnsubscribeAwake>(standardComponents.MainQueue));
                }
                coreOutput.Subscribe <TimerMessage.Schedule>(standardComponents.TimerService);


                coreOutput.Subscribe(Forwarder.Create <Message>(coreQueue)); // forward all

                coreInputBus.Subscribe(new UnwrapEnvelopeHandler());

                coreQueues.Add(workerId, coreQueue);
            }
            var queues      = coreQueues.Select(v => v.Value).Cast <IPublisher>().ToArray();
            var coordinator = new ProjectionCoreCoordinator(
                projectionsStandardComponents.RunProjections,
                coreTimeoutSchedulers,
                queues,
                projectionsStandardComponents.MasterOutputBus,
                new PublishEnvelope(projectionsStandardComponents.MasterInputQueue, crossThread: true));

            coordinator.SetupMessaging(projectionsStandardComponents.MasterMainBus);
            projectionsStandardComponents.MasterMainBus.Subscribe(
                Forwarder.CreateBalancing <FeedReaderMessage.ReadPage>(coreQueues.Values.Cast <IPublisher>().ToArray()));
            return(coreQueues);
        }
예제 #7
0
        private void SetupMessaging(
            TFChunkDb db, QueuedHandler mainQueue, InMemoryBus mainBus, TimerService timerService,
            HttpService httpService)
        {
            _coreQueues        = new List <QueuedHandler>();
            _managerInputBus   = new InMemoryBus("manager input bus");
            _managerInputQueue = new QueuedHandler(_managerInputBus, "ProjectionManager");

            while (_coreQueues.Count < _projectionWorkerThreadCount)
            {
                var coreInputBus   = new InMemoryBus("bus");
                var coreQueue      = new QueuedHandler(coreInputBus, "ProjectionCoreQueue #" + _coreQueues.Count);
                var projectionNode = new ProjectionWorkerNode(db, coreQueue);
                projectionNode.SetupMessaging(coreInputBus);


                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: coreQueue, externalRequestQueue: mainQueue);
                // forwarded messages
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadEvent>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadAllEventsForward>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.WriteEvents>(forwarder);

                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <CoreProjectionManagementMessage.StateReport>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <CoreProjectionManagementMessage.StatisticsReport>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <CoreProjectionManagementMessage.Started>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <CoreProjectionManagementMessage.Stopped>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <CoreProjectionManagementMessage.Faulted>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <CoreProjectionManagementMessage.Prepared>(_managerInputQueue));

                projectionNode.CoreOutput.Subscribe(timerService);


                projectionNode.CoreOutput.Subscribe(Forwarder.Create <Message>(coreQueue)); // forward all

                coreInputBus.Subscribe(new UnwrapEnvelopeHandler());

                _coreQueues.Add(coreQueue);
            }


            _projectionManagerNode = ProjectionManagerNode.Create(
                db, _managerInputQueue, httpService, _coreQueues.Cast <IPublisher>().ToArray());
            _projectionManagerNode.SetupMessaging(_managerInputBus);
            {
                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: _managerInputQueue, externalRequestQueue: mainQueue);
                _projectionManagerNode.Output.Subscribe <ClientMessage.ReadEvent>(forwarder);
                _projectionManagerNode.Output.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                _projectionManagerNode.Output.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                _projectionManagerNode.Output.Subscribe <ClientMessage.WriteEvents>(forwarder);
                _projectionManagerNode.Output.Subscribe(Forwarder.Create <Message>(_managerInputQueue));
                // self forward all

                mainBus.Subscribe(Forwarder.Create <SystemMessage.StateChangeMessage>(_managerInputQueue));
                _managerInputBus.Subscribe(new UnwrapEnvelopeHandler());
            }
        }
예제 #8
0
        public void SetupMessaging(IBus coreInputBus)
        {
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.CheckpointSuggested>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.CommittedEventReceived>());
            coreInputBus.Subscribe(
                _subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.EofReached>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.PartitionEofReached>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.PartitionDeleted>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.ProgressChanged>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.SubscriptionStarted>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.NotAuthorized>());
            coreInputBus.Subscribe(_subscriptionDispatcher
                                   .CreateSubscriber <EventReaderSubscriptionMessage.ReaderAssignedReader>());
            coreInputBus.Subscribe(_subscriptionDispatcher.CreateSubscriber <EventReaderSubscriptionMessage.Failed>());

            coreInputBus.Subscribe(_feedReaderService);

            if (_runProjections >= ProjectionType.System)
            {
                coreInputBus.Subscribe <ProjectionCoreServiceMessage.StartCore>(_projectionCoreService);
                coreInputBus.Subscribe <ProjectionCoreServiceMessage.StopCore>(_projectionCoreService);
                coreInputBus.Subscribe <ProjectionCoreServiceMessage.StopCoreTimeout>(_projectionCoreService);
                coreInputBus.Subscribe <ProjectionCoreServiceMessage.CoreTick>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.CreateAndPrepare>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.CreatePrepared>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.Dispose>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.Start>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.LoadStopped>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.Stop>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.Kill>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.GetState>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionManagementMessage.GetResult>(_projectionCoreService);
                coreInputBus.Subscribe <ClientMessage.ReadStreamEventsForwardCompleted>(_ioDispatcher.ForwardReader);
                coreInputBus.Subscribe <ClientMessage.ReadStreamEventsBackwardCompleted>(_ioDispatcher.BackwardReader);
                coreInputBus.Subscribe <ClientMessage.ReadEventCompleted>(_ioDispatcher.EventReader);
                coreInputBus.Subscribe <ClientMessage.WriteEventsCompleted>(_ioDispatcher.Writer);
                coreInputBus.Subscribe <ClientMessage.DeleteStreamCompleted>(_ioDispatcher.StreamDeleter);
                coreInputBus.Subscribe <IODispatcherDelayedMessage>(_ioDispatcher.Awaker);
                coreInputBus.Subscribe <IODispatcherDelayedMessage>(_ioDispatcher);
                coreInputBus.Subscribe <CoreProjectionProcessingMessage.CheckpointCompleted>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionProcessingMessage.CheckpointLoaded>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionProcessingMessage.PrerecordedEventsLoaded>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionProcessingMessage.RestartRequested>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionProcessingMessage.Failed>(_projectionCoreService);
                coreInputBus.Subscribe <CoreProjectionStatusMessage.Suspended>(_projectionCoreService);
                //NOTE: message forwarding is set up outside (for Read/Write events)

                // Forward messages back to projection manager
                coreInputBus.Subscribe(
                    Forwarder.Create <ProjectionManagementMessage.Command.ControlMessage>(_leaderOutputBus));
                coreInputBus.Subscribe(
                    Forwarder.Create <CoreProjectionStatusMessage.CoreProjectionStatusMessageBase>(_leaderOutputBus));
                coreInputBus.Subscribe(
                    Forwarder.Create <CoreProjectionStatusMessage.DataReportBase>(_leaderOutputBus));
            }

            coreInputBus.Subscribe <ReaderCoreServiceMessage.StartReader>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderCoreServiceMessage.StopReader>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionManagement.Subscribe>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionManagement.Unsubscribe>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionManagement.Pause>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionManagement.Resume>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.CommittedEventDistributed>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.EventReaderIdle>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.EventReaderStarting>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.EventReaderEof>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.EventReaderPartitionEof>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.EventReaderPartitionDeleted>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.EventReaderNotAuthorized>(_eventReaderCoreService);
            coreInputBus.Subscribe <ReaderSubscriptionMessage.Faulted>(_eventReaderCoreService);
            //NOTE: message forwarding is set up outside (for Read/Write events)
        }
예제 #9
0
        private void SetupMessaging(
            TFChunkDb db, QueuedHandler mainQueue, ISubscriber mainBus, TimerService timerService, ITimeProvider timeProvider,
            IHttpForwarder httpForwarder, HttpService[] httpServices, IPublisher networkSendQueue, RunProjections runProjections)
        {
            _coreQueues        = new List <QueuedHandler>();
            _managerInputBus   = new InMemoryBus("manager input bus");
            _managerInputQueue = new QueuedHandler(_managerInputBus, "Projections Master");
            while (_coreQueues.Count < _projectionWorkerThreadCount)
            {
                var coreInputBus = new InMemoryBus("bus");
                var coreQueue    = new QueuedHandler(
                    coreInputBus, "Projection Core #" + _coreQueues.Count, groupName: "Projection Core");
                var projectionNode = new ProjectionWorkerNode(db, coreQueue, timeProvider, runProjections);
                projectionNode.SetupMessaging(coreInputBus);


                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: coreQueue, externalRequestQueue: mainQueue);
                // forwarded messages
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadEvent>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.ReadAllEventsForward>(forwarder);
                projectionNode.CoreOutput.Subscribe <ClientMessage.WriteEvents>(forwarder);


                if (runProjections >= RunProjections.System)
                {
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.StateReport>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.ResultReport>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.StatisticsReport>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.Started>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.Stopped>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.Faulted>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.Prepared>(_managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <CoreProjectionManagementMessage.SlaveProjectionReaderAssigned>(
                            _managerInputQueue));
                    projectionNode.CoreOutput.Subscribe(
                        Forwarder.Create <ProjectionManagementMessage.ControlMessage>(_managerInputQueue));
                }
                projectionNode.CoreOutput.Subscribe <TimerMessage.Schedule>(timerService);


                projectionNode.CoreOutput.Subscribe(Forwarder.Create <Message>(coreQueue)); // forward all

                coreInputBus.Subscribe(new UnwrapEnvelopeHandler());

                _coreQueues.Add(coreQueue);
            }

            _managerInputBus.Subscribe(
                Forwarder.CreateBalancing <FeedReaderMessage.ReadPage>(_coreQueues.Cast <IPublisher>().ToArray()));

            _projectionManagerNode = ProjectionManagerNode.Create(
                db, _managerInputQueue, httpForwarder, httpServices, networkSendQueue,
                _coreQueues.Cast <IPublisher>().ToArray(), runProjections);
            _projectionManagerNode.SetupMessaging(_managerInputBus);
            {
                var forwarder = new RequestResponseQueueForwarder(
                    inputQueue: _managerInputQueue, externalRequestQueue: mainQueue);
                _projectionManagerNode.Output.Subscribe <ClientMessage.ReadEvent>(forwarder);
                _projectionManagerNode.Output.Subscribe <ClientMessage.ReadStreamEventsBackward>(forwarder);
                _projectionManagerNode.Output.Subscribe <ClientMessage.ReadStreamEventsForward>(forwarder);
                _projectionManagerNode.Output.Subscribe <ClientMessage.WriteEvents>(forwarder);
                _projectionManagerNode.Output.Subscribe(
                    Forwarder.Create <ProjectionManagementMessage.RequestSystemProjections>(mainQueue));
                _projectionManagerNode.Output.Subscribe(Forwarder.Create <Message>(_managerInputQueue));

                _projectionManagerNode.Output.Subscribe <TimerMessage.Schedule>(timerService);

                // self forward all

                mainBus.Subscribe(Forwarder.Create <SystemMessage.StateChangeMessage>(_managerInputQueue));
                _managerInputBus.Subscribe(new UnwrapEnvelopeHandler());
            }
        }