public AssembledComponents AssembleComponents() { var documents = CreateNuclear(new DocumentStrategy()); var streamer = Streamer; var tapes = Tapes; var streaming = Streaming; var routerQueue = CreateQueueWriter(Topology.RouterQueue); var aggregates = new AggregateFactory(tapes, streamer, routerQueue); var sender = new SimpleMessageSender(streamer, routerQueue); var flow = new MessageSender(sender); var builder = new CqrsEngineBuilder(streamer); var log = tapes.GetOrCreateStream(Topology.DomainLogName); var dispatcher = new SimpleDispatcher(aggregates, streamer, log); builder.Handle(CreateInbox(Topology.RouterQueue), Topology.Route(CreateQueueWriter, streamer, tapes), "router"); builder.Handle(CreateInbox(Topology.EntityQueue), aggregates.Dispatch); var functions = new RedirectToDynamicEvent(); // documents //functions.WireToWhen(new RegistrationUniquenessProjection(atomic.Factory.GetEntityWriter<unit, RegistrationUniquenessDocument>())); // UI projections var projectionStore = CreateNuclear(new ProjectionStrategy()); foreach (var projection in BootstrapProjections.BuildProjectionsWithWhenConvention(projectionStore.Factory)) { functions.WireToWhen(projection); } // processes //functions.WireToWhen(new Domain.RecipeProcess(flow)); builder.Handle(CreateInbox(Topology.EventsQueue), aem => CallHandlers(functions, aem)); var timer = new StreamingTimerService(CreateQueueWriter(Topology.RouterQueue), streaming.GetContainer(Topology.FutureMessagesContainer), streamer); builder.Handle(CreateInbox(Topology.TimerQueue), timer.PutMessage); builder.AddProcess(timer); // GNS: just for this simple sample. In reality one would have some command handlers involved Bus.SetBus(new SimpleBus(sender, dispatcher)); return(new AssembledComponents { Builder = builder, Sender = sender, Dispatcher = dispatcher, ProjectionFactory = projectionStore.Factory, Setup = this }); }
DirectoryInfo[] ObserveViews(ViewMapInfo[] handlers, DomainQueryManager queryManager) { WriteLine("Configuring {0} view handlers", handlers.Length); var name = string.Format("view-{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now); var combined = Path.Combine(Path.GetTempPath(), name); WriteLine("Redirecting atomic views to {0}", combined); var directoryInfo = new DirectoryInfo(combined); var file = FileStorage.CreateConfig(combined, reset: true); var nuclear = file.CreateNuclear(new ProjectionStrategy()); var watch = Stopwatch.StartNew(); var projectionTypes = new HashSet <Type>(handlers.Select(v => v.Projection)); WriteLine("Building consumers..."); var projections = BootstrapProjections.BuildProjectionsWithWhenConvention(nuclear.Factory).Where( x => projectionTypes.Contains(x.GetType())); var wire = new RedirectToDynamicEvent(); foreach (var projection in projections) { wire.WireToWhen(projection); } var handlersWatch = Stopwatch.StartNew(); queryManager.QueryConsumer(envelope => CallHandlers(wire, envelope)); WriteLine("Saved to {0}.", directoryInfo.FullName); var timeTotal = watch.Elapsed.TotalSeconds; var handlerTicks = handlersWatch.ElapsedTicks; var timeInHandlers = Math.Round(TimeSpan.FromTicks(handlerTicks).TotalSeconds, 1); WriteLine("Total Elapsed: {0}sec ({1}sec in handlers)", Math.Round(timeTotal, 0), timeInHandlers); WriteLine("Saved to {0}.", directoryInfo.FullName); var directoryInfos = handlers .Select(h => _strategy.GetFolderForEntity(h.ViewType, h.KeyType)) .Distinct() .Select(f => new DirectoryInfo(Path.Combine(directoryInfo.FullName, f.ToString()))) .ToArray(); return(directoryInfos); }
public static IEnumerable <ViewMapInfo> GetActiveViewMaps() { var marker = new AtomicDetector(); var projections = BootstrapProjections.BuildProjectionsWithWhenConvention(marker) .ToArray(); int idx = 0; foreach (var projection in projections) { var redirect = new RedirectToDynamicEvent(); redirect.WireToWhen(projection); var mark = marker.List[idx]; yield return(new ViewMapInfo(mark.Item2, mark.Item1, projection.GetType(), redirect.Dict.Keys.ToArray()) ); idx += 1; } }
static void Main(string[] args) { const string integrationPath = @"temp"; ConfigureObserver(); var config = FileStorage.CreateConfig(integrationPath, "files"); var demoMessages = new List <ISampleMessage>(); var currentProcess = Process.GetCurrentProcess(); demoMessages.Add(new InstanceStarted("Inject git rev", currentProcess.ProcessName, currentProcess.Id.ToString())); { // wipe all folders config.Reset(); Console.WriteLine("Starting in funny mode"); var security = new SecurityId(0); demoMessages.Add(new CreateSecurityAggregate(security)); demoMessages.Add(new AddSecurityPassword(security, "Rinat Abdullin", "*****@*****.**", "password")); demoMessages.Add(new AddSecurityIdentity(security, "Rinat's Open ID", "http://abdullin.myopenid.org")); demoMessages.Add(new AddSecurityKey(security, "some key")); } var atomic = config.CreateNuclear(new DocumentStrategy()); var identity = new IdentityGenerator(atomic); var streamer = Contracts.CreateStreamer(); var tapes = config.CreateTape(Topology.TapesContainer); var streaming = config.CreateStreaming(); var routerQueue = config.CreateQueueWriter(Topology.RouterQueue); var aggregates = new AggregateFactory(tapes, streamer, routerQueue, atomic, identity); var sender = new SimpleMessageSender(streamer, routerQueue); var flow = new MessageSender(sender); var builder = new CqrsEngineBuilder(streamer); builder.Handle(config.CreateInbox(Topology.RouterQueue), Topology.Route(config.CreateQueueWriter, streamer, tapes), "router"); builder.Handle(config.CreateInbox(Topology.EntityQueue), aggregates.Dispatch); var functions = new RedirectToDynamicEvent(); // documents //functions.WireToWhen(new RegistrationUniquenessProjection(atomic.Factory.GetEntityWriter<unit, RegistrationUniquenessDocument>())); // UI projections var projectionStore = config.CreateNuclear(new ProjectionStrategy()); foreach (var projection in BootstrapProjections.BuildProjectionsWithWhenConvention(projectionStore.Factory)) { functions.WireToWhen(projection); } // processes //functions.WireToWhen(new BillingProcess(flow)); //functions.WireToWhen(new RegistrationProcess(flow)); functions.WireToWhen(new ReplicationProcess(flow)); builder.Handle(config.CreateInbox(Topology.EventsQueue), aem => CallHandlers(functions, aem)); var timer = new StreamingTimerService(config.CreateQueueWriter(Topology.RouterQueue), streaming.GetContainer(Topology.FutureMessagesContainer), streamer); builder.Handle(config.CreateInbox(Topology.TimerQueue), timer.PutMessage); builder.AddProcess(timer); using (var cts = new CancellationTokenSource()) using (var engine = builder.Build()) { var task = engine.Start(cts.Token); foreach (var sampleMessage in demoMessages) { sender.SendOne(sampleMessage); } Console.WriteLine(@"Press enter to stop"); Console.ReadLine(); cts.Cancel(); if (task.Wait(5000)) { Console.WriteLine(@"Terminating"); } } }