Exemple #1
0
        public static void Run()
        {
            var clusterVNode = EmbeddedVNodeBuilder
                               .AsSingleNode()
                               .RunInMemory()
                               .WithWorkerThreads(1)
                               .Build();

            clusterVNode.StartAsync(true).Wait();


            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
                         .WriteTo.Console()
                         .CreateLogger();

            var loggerFactory = new LoggerFactory().AddSerilog(Log.Logger);

            var eventTypeProvider = new DefaultEventTypeProvider <EventCountAggregate>(() => new[] { typeof(EventCountOne), typeof(EventCountTwo) });;

            var eventCountActor = EventStoreEmbeddedStatefulActorBuilder <EventCountStatefulActor, EventCountAggregate, DemoSystemRegistry>
                                  .Create(clusterVNode, Do.GetConnectionSettings(), ActorConfiguration.Default, loggerFactory)
                                  .WithReadAllFromStartCache(
                eventTypeProvider: eventTypeProvider,
                getCatchupEventStoreCacheConfigurationBuilder: builder => builder.KeepAppliedEventsOnAggregate = true)
                                  .Build();

            Do.Run(eventCountActor);
        }
Exemple #2
0
        public static void Run()
        {
            var clusterVNode = EmbeddedVNodeBuilder
                               .AsSingleNode()
                               .RunInMemory()
                               .WithWorkerThreads(1)
                               .Build();

            clusterVNode.StartAsync(true).Wait();

            var eventTypeProvider = new DefaultEventTypeProvider <EventCountAggregate>(() => new[] { typeof(EventCountOne), typeof(EventCountTwo) });;

            var eventCountActor = EventStoreEmbeddedStatefulActorBuilder <EventCountStatefulActor, EventCountAggregate, DemoSystemRegistry>
                                  .Create(clusterVNode, Do.GetConnectionSettings(), ActorConfiguration.Default)
                                  .WithReadAllFromEndCache(
                eventTypeProvider: eventTypeProvider,
                getSubscribeFromEndCacheConfiguration: builder => builder.KeepAppliedEventsOnAggregate = true)
                                  .Build();

            Do.Run(eventCountActor);
        }
Exemple #3
0
        public async Task ShouldRegisterABusOnAStatefulActor()
        {
            var testBusRegistrationActor = EventStoreEmbeddedStatefulActorBuilder <TestBusRegistrationStatefulActor, SomeDataAggregate, DummyBusRegistry>
                                           .Create(_clusterVNode, _connectionSettings, ActorConfiguration.Default, _loggerFactory)
                                           .WithReadAllFromEndCache(new ConsumerBasedEventProvider <SomeDataAggregate, TestBusRegistrationStatefulActor>())
                                           .WithBus <IDummyBus>((actor, bus) =>
            {
                actor.SubscribeDummyBus("somesubject");
            })
                                           .Build();

            var dummyBus = testBusRegistrationActor.GetConnectedBus <IDummyBus>();

            dummyBus.Push(new SomeData("entity", Guid.NewGuid()));

            await Task.Delay(200);

            Assert.AreEqual(1, testBusRegistrationActor.Events.Count);

            testBusRegistrationActor.Dispose();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //var dispatchQueue = new DispatchQueue<int>(new DispatchQueueConfiguration<int>((i=>
            //{
            //    throw new Exception("boom");

            //}),1,1));

            //dispatchQueue.Enqueue(1);


            Task.Run(() =>
            {
                var connectionSettings = StaticData.GetConnectionSettings();

                var tradeDataEventProvider  = new DefaultEventTypeProvider <Trade>(() => new[] { typeof(TradeCreated), typeof(TradeStatusChanged) });
                var marketDataEventProvider = new DefaultEventTypeProvider <MarketData>(() => new[] { typeof(MarketDataChanged) });

                var tradeService = EventStoreEmbeddedStatelessActorBuilder <TradeService, DemoSystemRegistry>
                                   .Create(StaticData.ClusterVNode, connectionSettings, ActorConfiguration.Default)
                                   .WithBus <IEventStoreBus>((actor, bus) =>
                {
                    actor.SubscribeFromEndToAllStreams();
                })
                                   .Build();

                var tradePriceUpdateService = EventStoreEmbeddedStatefulActorBuilder <TradePriceUpdateService, Trade, DemoSystemRegistry>
                                              .Create(StaticData.ClusterVNode, connectionSettings, ActorConfiguration.Default)
                                              .WithReadAllFromStartCache(eventTypeProvider: tradeDataEventProvider)
                                              .WithBus <IEventStoreBus>((actor, bus) =>
                {
                    actor.SubscribeFromEndToAllStreams();
                })
                                              .WithBus <IMarketDataBus>((actor, bus) =>
                {
                    actor.SubscribeMarketDataBus();
                })
                                              .Build();

                var tradeSink = EventStoreEmbeddedStatefulActorBuilder <TradeSink, Trade, DemoSystemRegistry>
                                .Create(StaticData.ClusterVNode, connectionSettings, ActorConfiguration.Default)
                                .WithReadAllFromStartCache(eventTypeProvider: tradeDataEventProvider)
                                .Build();

                var marketDataSink = StatelessActorBuilder <MarketDataSink, DemoSystemRegistry>
                                     .Create(ActorConfiguration.Default)
                                     .WithBus <IMarketDataBus>((actor, bus) =>
                {
                    actor.SubscribeMarketDataBus();
                })
                                     .Build();

                var marketDataCache = marketDataSink.CurrentPrices.Connect();
                var tradeCache      = tradeSink.State.AsObservableCache().Connect();

                tradeCache.PrintTradeChanges();
                marketDataCache.PrintMarketDataChanges();
            });

            Console.Read();
        }
        public async Task ShouldBuildFromActorBuilderAndRunActors()
        {
            var defaultEventTypeProvider = new DefaultEventTypeProvider <SomeDataAggregate>(() => new[] { typeof(SomeData) });

            var testActorAutoBuildOne = EventStoreEmbeddedStatefulActorBuilder <TestStatefulActorOne, SomeDataAggregate, SomeRegistry> .Create(_clusterVNode, _connectionSettings, ActorConfiguration.Default, _loggerFactory)
                                        .WithReadAllFromStartCache(
                getCatchupEventStoreCacheConfigurationBuilder: (conf) => conf.KeepAppliedEventsOnAggregate = true,
                eventTypeProvider: new DefaultEventTypeProvider <SomeDataAggregate>(() => new[] { typeof(SomeData) }))
                                        .WithBus <IEventStoreBus>((actor, bus) =>
            {
                actor.SubscribeFromEndToAllStreams();
                actor.SubscribeToPersistentSubscriptionStream(_streamId2, _groupIdOne);
            })
                                        .Build();

            var testActorAutoBuildTwo = EventStoreEmbeddedStatefulActorBuilder <TestAggregatedActorTwo, SomeDataAggregate, SomeRegistry> .Create(_clusterVNode, _connectionSettings, ActorConfiguration.Default, _loggerFactory)
                                        .WithReadAllFromStartCache(
                getCatchupEventStoreCacheConfigurationBuilder: (conf) => conf.KeepAppliedEventsOnAggregate = true,
                eventTypeProvider: new DefaultEventTypeProvider <SomeDataAggregate>(() => new[] { typeof(SomeData) }))
                                        .WithBus <IEventStoreBus>((actor, bus) =>
            {
                actor.SubscribeFromEndToAllStreams();
            })
                                        .Build();

            await testActorAutoBuildTwo.EmitEventStore(new SomeMoreData(_correlationId, "some-stream"));

            await Task.Delay(1000);

            Assert.AreEqual(1, testActorAutoBuildOne.Events.Count);

            await testActorAutoBuildTwo.EmitEventStore(new SomeMoreData(_correlationId, _streamId2));

            await Task.Delay(1500);

            Assert.AreEqual(3, testActorAutoBuildOne.Events.Count);

            var aggregateOne = Guid.NewGuid();
            var aggregateTwo = Guid.NewGuid();

            await testActorAutoBuildOne.EmitEventStore(new SomeData($"{aggregateOne}", _correlationId));

            await testActorAutoBuildOne.EmitEventStore(new SomeData($"{aggregateTwo}", _correlationId));

            await Task.Delay(500);

            Assert.AreEqual(2, testActorAutoBuildOne.State.GetCurrents().Length);
            Assert.AreEqual(2, testActorAutoBuildTwo.State.GetCurrents().Length);

            Assert.AreEqual(1, testActorAutoBuildOne.State.GetCurrent($"{aggregateOne}").AppliedEvents.Length);
            Assert.AreEqual(1, testActorAutoBuildTwo.State.GetCurrent($"{aggregateTwo}").AppliedEvents.Length);

            await testActorAutoBuildOne.EmitEventStore(new SomeData($"{aggregateOne}", _correlationId));

            await testActorAutoBuildOne.EmitEventStore(new SomeData($"{aggregateTwo}", _correlationId));

            await Task.Delay(1000);

            Assert.AreEqual(2, testActorAutoBuildOne.State.GetCurrents().Length);
            Assert.AreEqual(2, testActorAutoBuildTwo.State.GetCurrents().Length);

            Assert.AreEqual(2, testActorAutoBuildOne.State.GetCurrent($"{aggregateOne}").AppliedEvents.Length);
            Assert.AreEqual(2, testActorAutoBuildTwo.State.GetCurrent($"{aggregateTwo}").AppliedEvents.Length);

            testActorAutoBuildOne.Dispose();
            testActorAutoBuildTwo.Dispose();
        }