protected override void EngineConfig(CqrsEngineBuilder b)
 {
     b.Storage(m => m.AtomicIsInFiles(_path, DefaultWithCustomConfig));
     b.Memory(m =>
     {
         m.AddMemoryProcess("azure-dev");
         m.AddMemorySender("azure-dev", x => x.IdGeneratorForTests());
     });
 }
예제 #2
0
        protected override void EngineConfig(CqrsEngineBuilder b)
        {
            var account = AzureStorage.CreateConfigurationForDev();

            WipeAzureAccount.Fast(s => s.StartsWith("test-"), account);

            b.Azure(m =>
            {
                m.AddAzureProcess(account, new[] { "test-incoming" }, c => c.QueueVisibility(1));
                m.AddAzureSender(account, "test-incoming", x => x.IdGeneratorForTests());
            });
            b.Storage(m => m.AtomicIsInAzure(account, DefaultWithCustomConfig));
        }
예제 #3
0
        public static CqrsEngineBuilder Configure(FileStorageConfig cache)
        {
            var observer = new ImmediateEventsObserver();

            observer.Event += @event =>
            {
                var failed = @event as EnvelopeDispatchFailed;

                if (failed != null)
                {
                    Trace.WriteLine(failed.Exception);
                }
            };

            var builder = new CqrsEngineBuilder();

            builder.Advanced.RegisterObserver(observer);
            builder.Advanced.RegisterQueueWriterFactory(context => new FileQueueWriterFactory(cache, context.Resolve <IEnvelopeStreamer>()));
            builder.Domain(m =>
            {
                m.HandlerSample <IConsume <IBaseMessage> >(c => c.Consume(null));
                m.InAssemblyOf <StoryViewHandler>();
                m.InAssemblyOf <AddNote>();
                m.InAssemblyOf <StoryList>();
            });
            builder.Advanced.CustomDataSerializer(t => new DataSerializerWithProtoBuf(t));
            builder.Advanced.CustomEnvelopeSerializer(new EnvelopeSerializerWithProtoBuf());
            builder.Storage(c =>
            {
                RegisterAtomicStorage(cache, c);
                c.TapeIsInFiles(Path.Combine(cache.Folder.FullName, "tapes"));
            });

            builder.File(m =>
            {
                m.AddFileSender(cache, "router", cm => cm.IdGeneratorForTests());
                m.AddFileProcess(cache, "router", x => x.DispatcherIsLambda(SaveAndRoute));
                m.AddFileProcess(cache, "events", p => p.DispatchAsEvents(md => md.WhereMessagesAre <IEvent>()));
                m.AddFileProcess(cache, "aggregates", p => p.DispatcherIs(context =>
                {
                    var readers  = context.Resolve <ITapeStorageFactory>();
                    var streamer = context.Resolve <IEnvelopeStreamer>();
                    var reg      = context.Resolve <QueueWriterRegistry>();
                    return(new AggregateDispatcher(readers, streamer, "files:router", reg));
                }));
            });
            return(builder);
        }
예제 #4
0
        protected override CqrsEngineHost BuildHost()
        {
            var builder = new CqrsEngineBuilder();

            //NOTE: Core Lokad CQRS Initialization
            builder.UseProtoBufSerialization();

            builder.Domain(config =>
            {
                config.InAssemblyOf <CreateMessage>();
                config.InAssemblyOf <CreateMessageHandler>();
                config.ContextFactory(MyMessageContext.Factory);
            });

            var storageConfig = CreateCloudStorageConfig();

            builder.Azure(config =>
            {
                config.AddAzureProcess(storageConfig, Queues.MESSAGES);
                config.AddAzureSender(storageConfig, Queues.MESSAGES);
            });

            builder.Storage(config => config.AtomicIsInAzure(storageConfig, s =>
            {
                s.WithAssemblyOf <MessageView>();
                s.CustomStaticSerializer(new AtomicStorageSerializerWithProtoBuf());
            }));

            //NOTE: Event Store Initialization
            builder.ConfigureJonathanOliverEventStore(config =>
            {
                var connectionString = AzureSettingsProvider.GetString("EventStoreConnectionString");

                config.ConnectionString(connectionString);
                config.Hooks(p => p.Add <MyNullPipelineHook>());
                config.Snapshots(s =>
                {
                    //snapshotting isn't implemented correctly right now.
                    s.Disable();
                    s.CheckEvery(TimeSpan.FromSeconds(30));
                    //set this to something reasonable like 250.
                    //It's so low here to demonstrate background "out-of-band" snapshotting.
                    s.MaxThreshold(2);
                });
            });

            return(builder.Build());
        }
        public void Run_in_test()
        {
            var builder = new CqrsEngineBuilder();

            builder.Memory(m =>
            {
                m.AddMemorySender("work");
                m.AddMemoryProcess("work");
            });
            builder.Storage(m => m.AtomicIsInMemory());

            using (var engine = builder.Build())
            {
                //engine.Resolve<IMessageSender>().SendOne(new CreateCustomer()
                //{
                //    CustomerId = 1,
                //    CustomerName = "Rinat Abdullin"
                //});
                engine.RunForever();
            }
        }
예제 #6
0
        public void Test()
        {
            var builder = new CqrsEngineBuilder();

            builder.Domain(m =>
            {
                m.HandlerSample <Definitions.Define.Consumer <Definitions.Define.ICommand> >(c => c.Consume(null));
                m.ContextFactory((e, x) => new Definitions.Define.MyContext(e.GetAttribute("EntityId", "")));
            });
            builder.Storage(m => m.AtomicIsInMemory());
            builder.Memory(m =>
            {
                m.AddMemorySender("in", c => c.IdGeneratorForTests());
                m.AddMemoryProcess("in");
            });

            builder.Advanced.ConfigureContainer(cb =>
            {
                cb.Register(c => new InMemoryEventStreamer <IAccountEvent>(c.Resolve <IMessageSender>())).
                SingleInstance();

                cb.RegisterType <InMemoryEventStreamer <IAccountEvent> >().SingleInstance();
                cb.RegisterType <AccountAggregateRepository>().SingleInstance();
            });

            using (var source = new CancellationTokenSource())
                using (var engine = builder.Build())
                {
                    engine.Start(source.Token);

                    var sender = engine.Resolve <IMessageSender>();
                    sender.SendOne(new CreateAccount("Sample User"), cb => cb.AddString("EntityId", "1"));
                    sender.SendOne(new AddLogin("login", "pass"), cb => cb.AddString("EntityId", "1"));

                    source.Token.WaitHandle.WaitOne(5000);
                    source.Cancel();
                }
        }