Esempio n. 1
0
 static void Consume(CreateCustomer cmd, NuclearStorage storage, SimpleMessageSender sender)
 {
     var customer = new Customer(cmd.CustomerId, cmd.CustomerName);
     storage.AddEntity(customer.Id, customer);
     sender.SendOne(new CustomerCreated
         {
             CustomerId = cmd.CustomerId,
             CustomerName = cmd.CustomerName
         });
 }
Esempio n. 2
0
        protected static void HandleNuclear(NuclearMessage msg, SimpleMessageSender sender, NuclearStorage storage)
        {
            var count = storage.AddOrUpdateSingleton(() => 1, i => i + 1);

            if (count >= 2)
            {
                sender.SendBatch(new object[] {}, e => e.AddString("ok"));
                return;
            }
            sender.SendOne(new NuclearMessage());
        }
Esempio n. 3
0
        protected static void HandleAtomic(AtomicMessage msg, SimpleMessageSender sender, IAtomicWriter <unit, int> arg3)
        {
            var count = arg3.AddOrUpdate(unit.it, () => 1, i => i + 1);

            if (count > 2)
            {
                sender.SendBatch(new object[] {}, e => e.AddString("ok"));
                return;
            }
            sender.SendOne(new AtomicMessage());
        }
Esempio n. 4
0
        public void SendCommand(ICommand message)
        {
            Log("BUS", "Sending '{0}'\r\n{1}", message.GetType().Name, JsonSerializer.SerializeToString(message));

            _client.SendOne(message);
        }
 public void SendOne(object content)
 {
     _sender.SendOne(content);
 }
 public void Schedule(IRecipeCommand command, DateTime dateUtc)
 {
     _sender.SendOne(command, eb => eb.DeliverOnUtc(dateUtc));
 }
Esempio n. 7
0
        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");
                    }
                }
        }