private static CqrsEngineBuilder GetBuilder()
        {
            var builder = new CqrsEngineBuilder();

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

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

            builder.Memory(config =>
            {
                config.AddMemoryProcess(Queues.MESSAGES, d=>{});
                config.AddMemorySender(Queues.MESSAGES);
            });

            builder.Storage(config =>
            {
                var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "storage");
                if (!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);

                config.AtomicIsInFiles(folder, s =>
                {
                    s.NameForSingleton(type => DefaultAtomicStorageStrategyBuilder.CleanName(type.Name) + ".json");
                    s.NameForEntity((type, key) => (DefaultAtomicStorageStrategyBuilder.CleanName(type.Name) + "-" + Convert.ToString(key, CultureInfo.InvariantCulture).ToLowerInvariant()) + ".json");
                    s.WithAssemblyOf<MessageView>();
                    s.CustomStaticSerializer(new AtomicStorageSerializerWithJson());
                });
                config.StreamingIsInFiles(folder);
            });

            //NOTE: Event Store Initialization
            builder.ConfigureJonathanOliverEventStore(config =>
            {
                const string CONNECTION_STRING = @"Data Source=.\sqlexpress;Initial Catalog=lokad-cqrs-eventstore;Integrated Security=True";

                config.ConnectionString(CONNECTION_STRING);
                config.Hooks(p => p.Add<MyNullPipelineHook>());
                config.Snapshots(s =>
                {
                    s.Enable();
                    s.AggregateTypeResolver(typeName => Type.GetType(typeName + ",Domain"));
                    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(5);
                });
            });

            return builder;
        }
        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();
        }
示例#3
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());
        }
        static void TestConfiguration(Action <CqrsEngineBuilder> build)
        {
            var builder = new CqrsEngineBuilder();

            builder.UseProtoBufSerialization();
            build(builder);


            var subj = new Subject <ISystemEvent>();

            builder.Advanced.Observers.Clear();
            builder.Advanced.RegisterObserver(subj);
            int count = 0;

            subj
            .OfType <EnvelopeAcked>()
            .Subscribe(acked => count += 1);

            var watch = new Stopwatch();

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

                    engine
                    .Resolve <IMessageSender>()
                    .SendOne(new UsualMessage());

                    watch.Start();
                    token.Token.WaitHandle.WaitOne(5000);
                }

            watch.Stop();
            var messagesPerSecond = count / watch.Elapsed.TotalSeconds;
            var round             = Math.Round(messagesPerSecond, 1);

            Console.WriteLine("{0} messages per second", round);
        }