コード例 #1
0
        static async Task Main(string[] args)
        {
            var eventStoreConnection = EventStoreConnectionFactory.Create(
                new EventStoreSingleNodeConfiguration(),
                new ConsoleLogger(),
                "admin", "changeit");

            await eventStoreConnection.ConnectAsync();

            _eventStore = new Bank.Persistence.EventStore.EventStore(eventStoreConnection, new List <IEventSchema>
            {
                new AccountSchema()
            });
            _accountSnapshotRepository = new AccountSnapshotRepository(_eventStore);

            var tasks = new Task[NumberOfStreams];

            for (int i = 0; i < NumberOfStreams; i++)
            {
                var number = i;
                tasks[i] = Task.Run(async() => { await CreateStreams(number); });
            }

            await Task.Delay(4000);

            Task.Run(async() =>
            {
                while (true)
                {
                    await Task.Delay(2000);

                    Console.WriteLine("-----Status-----");

                    for (int i = 0; i < 5; i++)
                    {
                        double readTimings = 0;
                        if (!ReadTimings[i].IsEmpty)
                        {
                            readTimings = Math.Floor(ReadTimings[i].Average());
                        }
                        double writeTimings = 0;
                        if (!WriteTimings[i].IsEmpty)
                        {
                            writeTimings = Math.Floor(WriteTimings[i].Average());
                        }

                        Console.WriteLine($"Stream: {i}, Balance: {Balances[i]}, Read: {readTimings} ms, Write: {writeTimings} ms");
                    }

                    ReadTimings  = CreateTimingsArray(NumberOfStreams);
                    WriteTimings = CreateTimingsArray(NumberOfStreams);
                }
            });

            await Task.WhenAll(tasks);

            Console.ReadLine();
        }
コード例 #2
0
        static async Task Main(string[] args)
        {
            var eventStoreSubscriptionConnection = EventStoreConnectionFactory.Create(
                new EventStoreSingleNodeConfiguration(),
                new ConsoleLogger(),
                "admin", "changeit");
            var eventStoreWriteConnection = EventStoreConnectionFactory.Create(
                new EventStoreSingleNodeConfiguration(),
                new ConsoleLogger(),
                "admin", "changeit");

            await eventStoreSubscriptionConnection.ConnectAsync();

            await eventStoreWriteConnection.ConnectAsync();

            _eventStore = new Bank.Persistence.EventStore.EventStore(eventStoreSubscriptionConnection, new List <IEventSchema>
            {
                new AccountSchema()
            });
            _repository = new AccountSnapshotRepository(_eventStore);

            try
            {
                await eventStoreSubscriptionConnection.CreatePersistentSubscriptionAsync(
                    "$ce-Account",
                    "Snapshot",
                    PersistentSubscriptionSettings
                    .Create()
                    .StartFromBeginning()
                    .CheckPointAfter(TimeSpan.FromSeconds(5))
                    .ResolveLinkTos()
                    .Build(), new UserCredentials("admin", "changeit"));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Subscription already exist.");
            }

            await eventStoreSubscriptionConnection.ConnectToPersistentSubscriptionAsync("$ce-Account", "Snapshot", EventAppeared);

            await eventStoreSubscriptionConnection.ConnectToPersistentSubscriptionAsync("$ce-Account", "Snapshot", EventAppeared);

            await eventStoreSubscriptionConnection.ConnectToPersistentSubscriptionAsync("$ce-Account", "Snapshot", EventAppeared);

            await eventStoreSubscriptionConnection.ConnectToPersistentSubscriptionAsync("$ce-Account", "Snapshot", EventAppeared);

            await eventStoreSubscriptionConnection.ConnectToPersistentSubscriptionAsync("$ce-Account", "Snapshot", EventAppeared);

            Console.ReadLine();
        }