Beispiel #1
0
        static void Main(string[] args)
        {
            var actorSystem = ActorSystem.Create("Sample");

            Task.Run(async () =>
            {
                // this is used to retrieve the events later
                var memoryStore = new InMemoryStore();

                // initialize the event store
                var gateway = await actorSystem
                    .SetupEven()
                    .UseStore(memoryStore)
                    .AddProjection<ActiveProducts>()
                    .Start("even");

                // send some commands
                await Task.WhenAll(
                    gateway.SendAggregateCommand<Product>(1, new CreateProduct { Name = "Product 1" }),
                    gateway.SendAggregateCommand<Product>(2, new CreateProduct { Name = "Product 2" }),
                    gateway.SendAggregateCommand<Product>(3, new CreateProduct { Name = "Product 3" }),
                    gateway.SendAggregateCommand<Product>(2, new RenameProduct { NewName = "Product 2 - Renamed" }),
                    gateway.SendAggregateCommand<Product>(1, new DeleteProduct())
                );

                // add some delay to make sure the data is flushed to the store 
                await Task.Delay(100);

                // print the contents of the event store
                Console.WriteLine();
                Console.WriteLine("Event Store Data");
                Console.WriteLine("================");
                Console.WriteLine();
                Console.WriteLine($"{"Seq",-6} {"Stream ID",-50} Event Name");

                foreach (var e in memoryStore.GetEvents())
                    Console.WriteLine($"{e.GlobalSequence,-6} {e.Stream,-50} {e.EventType}");

            }).Wait();

            Console.WriteLine();
            Console.WriteLine("End");
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.LiterateConsole()
                .CreateLogger();

            var actorSystem = ActorSystem.Create("SnackMachine");
            Task.Run(async () =>
            {
                var eventStore = new InMemoryStore();

                var gateway = await actorSystem
                    .SetupEven()
                    .UseStore(eventStore)
                    .Start("snacks");

                // Send some commands
                await Task.WhenAll(
                    gateway.SendAggregateCommand<SnackMachine>(1,
                        new SnackMachine.DeploySnackMachine(new Money(100,50,50,10,20,0))),
                    gateway.SendAggregateCommand<SnackMachine>(2,
                        new SnackMachine.DeploySnackMachine(new Money(100, 50, 20, 25, 10, 0)))
                    );

                // add some delay to make sure the data is flushed to the store 
                await Task.Delay(100);

                // print the contents of the event store
                Console.WriteLine();
                Console.WriteLine("Event Store Data");
                Console.WriteLine("================");
                Console.WriteLine();
                Console.WriteLine($"{"Seq",-6} {"Stream ID",-50} Event Name");

                foreach (var e in eventStore.GetEvents())
                    Console.WriteLine($"{e.GlobalSequence,-6} {e.Stream.Name,-50} {e.EventType}");

            }).Wait();

            Console.WriteLine();
            Console.WriteLine("Scenario Completed");
            Console.ReadLine();
        }