Beispiel #1
0
        public void SetUp()
        {
            _storeRecords         = new List <StoreRecord>();
            this._serializer      = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), typeof(string) });
            this._path            = Path.Combine(Path.GetTempPath(), "MessageStorePublisher", Guid.NewGuid().ToString());
            this._appendOnlyStore = new FileAppendOnlyStore(new DirectoryInfo(this._path));
            this._appendOnlyStore.Initialize();
            this._store = new MessageStore(this._appendOnlyStore, this._serializer);
            var streamer    = new EnvelopeStreamer(this._serializer);
            var queueWriter = new TestQueueWriter();

            this._sender = new MessageSender(streamer, queueWriter);
            var store = new FileDocumentStore(Path.Combine(this._path, "lokad-cqrs-test"), new DocumentStrategy());

            this._nuclearStorage = new NuclearStorage(store);

            this._publisher = new MessageStorePublisher("test-tape", this._store, this._sender, this._nuclearStorage, DoWePublishThisRecord);
        }
Beispiel #2
0
        public Container Build()
        {
            var appendOnlyStore = CreateTapes(TapesContainer);
            var messageStore    = new MessageStore(appendOnlyStore, Streamer.MessageSerializer);

            var toCommandRouter      = new MessageSender(Streamer, CreateQueueWriter(RouterQueue));
            var toFunctionalRecorder = new MessageSender(Streamer, CreateQueueWriter(FunctionalRecorderQueue));
            var toEventHandlers      = new MessageSender(Streamer, CreateQueueWriter(EventProcessingQueue));

            var sender = new TypedMessageSender(toCommandRouter, toFunctionalRecorder);

            var store = new EventStore(messageStore);

            var quarantine = new EnvelopeQuarantine(Streamer, sender, Streaming.GetContainer(ErrorsContainer));

            var builder = new CqrsEngineBuilder(Streamer, quarantine);

            var events   = new RedirectToDynamicEvent();
            var commands = new RedirectToCommand();
            var funcs    = new RedirectToCommand();


            builder.Handle(CreateInbox(EventProcessingQueue), aem => CallHandlers(events, aem), "watch");
            builder.Handle(CreateInbox(AggregateHandlerQueue), aem => CallHandlers(commands, aem));
            builder.Handle(CreateInbox(RouterQueue), MakeRouter(messageStore), "watch");
            // multiple service queues
            _serviceQueues.ForEach(s => builder.Handle(CreateInbox(s), aem => CallHandlers(funcs, aem)));

            builder.Handle(CreateInbox(FunctionalRecorderQueue), aem => RecordFunctionalEvent(aem, messageStore));
            var viewDocs  = CreateDocs(ViewStrategy);
            var stateDocs = new NuclearStorage(CreateDocs(DocStrategy));



            var vector = new DomainIdentityGenerator(stateDocs);
            //var ops = new StreamOps(Streaming);
            var projections = new ProjectionsConsumingOneBoundedContext();

            // Domain Bounded Context
            DomainBoundedContext.EntityApplicationServices(viewDocs, store, vector).ForEach(commands.WireToWhen);
            DomainBoundedContext.FuncApplicationServices().ForEach(funcs.WireToWhen);
            DomainBoundedContext.Ports(sender).ForEach(events.WireToWhen);
            DomainBoundedContext.Tasks(sender, viewDocs, true).ForEach(builder.AddTask);
            projections.RegisterFactory(DomainBoundedContext.Projections);

            // Client Bounded Context
            projections.RegisterFactory(ClientBoundedContext.Projections);

            // wire all projections
            projections.BuildFor(viewDocs).ForEach(events.WireToWhen);

            // wire in event store publisher
            var publisher = new MessageStorePublisher(messageStore, toEventHandlers, stateDocs, DoWePublishThisRecord);

            builder.AddTask(c => Task.Factory.StartNew(() => publisher.Run(c)));

            return(new Container
            {
                Builder = builder,
                Setup = this,
                SendToCommandRouter = toCommandRouter,
                MessageStore = messageStore,
                ProjectionFactories = projections,
                ViewDocs = viewDocs,
                Publisher = publisher,
                AppendOnlyStore = appendOnlyStore
            });
        }