예제 #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 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 <ProjectionMessage.Projections.Management.StateReport>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <ProjectionMessage.Projections.Management.StatisticsReport>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <ProjectionMessage.Projections.StatusReport.Started>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <ProjectionMessage.Projections.StatusReport.Stopped>(_managerInputQueue));
                projectionNode.CoreOutput.Subscribe(
                    Forwarder.Create <ProjectionMessage.Projections.StatusReport.Faulted>(_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.SystemInit>(_managerInputQueue));
                mainBus.Subscribe(Forwarder.Create <SystemMessage.SystemStart>(_managerInputQueue));
                mainBus.Subscribe(Forwarder.Create <SystemMessage.StateChangeMessage>(_managerInputQueue));
                _managerInputBus.Subscribe(new UnwrapEnvelopeHandler());
            }
        }