Пример #1
0
        static async Task Main(string[] args)
        {
            #pragma warning disable 4014
            Task.Run(async() => await RunStateChecker());
            #pragma warning restore 4014

            using var connection = await EventStoreHelpers.CreateConnection();

            await using var context = new AccountDbContext();

            await Task.Delay(TimeSpan.FromSeconds(3));

            //var withdrawAmount = 580;

            //var accountCheckpoint = await context
            //    .AccountStateCheckpoints
            //    .Include(checkpoint => checkpoint.AccountState)
            //    .FirstOrDefaultAsync(checkpoint => checkpoint.AccountStateId == AccountGuid);

            //if (accountCheckpoint.AccountState.MoneyAmount - withdrawAmount >= 0)
            //{
            //    var withdrawEvt = EventStoreHelpers.CreateEvent("Withdrawal", new
            //    {
            //        amount = withdrawAmount
            //    });

            //    var expectedEventNumber = accountCheckpoint.LastProcessedEventNumber;

            //    await connection.AppendToStreamAsync(StreamName, expectedEventNumber, withdrawEvt);
            //}

            Console.ReadLine();
        }
Пример #2
0
        static async Task Main(string[] args)
        {
            var order = new Order
            {
                Products = new List <Product>
                {
                    new Product {
                        Title = "Пицца", Price = 100
                    },
                    new Product {
                        Title = "Хот-дог", Price = 30
                    },
                }
            };

            var jsonOrder = JsonConvert.SerializeObject(order);

            //var result = await client.PostAsync("API_LINK", new StringContent(jsonOrder, Encoding.UTF8));

            using var connection = await EventStoreHelpers.CreateConnection();

            var streamName = $"order-{order.Id}";

            var evt = EventStoreHelpers.CreateEvent(nameof(EventType.OrderCreated), order);

            await Task.Delay(TimeSpan.FromSeconds(3));

            await connection.AppendToStreamAsync(streamName, ExpectedVersion.Any, evt);
        }
Пример #3
0
        static async Task RunStateChecker()
        {
            using var context = new AccountDbContext();
            await context.Database.EnsureCreatedAsync();

            using var connection = await EventStoreHelpers.CreateConnection();

            await ProcessLastEvents(connection, context);
        }
Пример #4
0
        static async Task Main(string[] args)
        {
            _connection = await EventStoreHelpers.CreateConnection();

            var stream = "$et-OrderCreated";

            await _connection.SubscribeToLinkedStream(stream, ProcessEvent);

            Console.WriteLine("processing events");
            Console.ReadLine();
        }
        private async Task CreateCompetingConsumersSubscription()
        {
            bool created = await EventStoreHelpers.CreatePersistentSubscriptionAsyncIfRequired(
                StreamId,
                GroupName,
                PersistentSubscriptionSettings.Create()
                .StartFromBeginning()
                .PreferRoundRobin()
                .Build(),
                Credentials,
                CreateConnection);

            if (created)
            {
                Logger.Warn("Created subscription for stream {0} using group name {1}", StreamId, GroupName);
            }
        }
Пример #6
0
        static async Task ProcessLastEvents(IEventStoreConnection connection, AccountDbContext context)
        {
            var isEndOfStream          = false;
            var lastProcessEventNumber = 0;
            var batchSize = 2;

            while (!isEndOfStream)
            {
                var oldEvents = await connection.ReadStreamEventsForwardAsync(
                    StreamName,
                    lastProcessEventNumber,
                    batchSize,
                    true,
                    EventStoreHelpers.GetCredentials());

                await UpdateState(oldEvents, context);

                lastProcessEventNumber += batchSize;

                isEndOfStream = oldEvents.IsEndOfStream;
            }
        }
Пример #7
0
        static async Task Main(string[] args)
        {
            using var connection = await EventStoreHelpers.CreateConnection();

            var stream = "my-first-stream";

            await connection.SubscribeToStream(stream, ProcessEvent);

            Console.WriteLine("processing events");
            Console.ReadLine();
            var pm    = EventStoreHelpers.CreateProjectionsManager();
            var creds = EventStoreHelpers.GetCredentials();

            var projection  = "money-for-accounts";
            var partitionId = "account-e3f62a80-a504-4cfb-97f1-b9a003535da8";
            var result      = await pm.GetPartitionResultAsync(projection, partitionId, creds);

            Console.WriteLine(result);

            // projection create from file sample
            //var fileStr = await File.ReadAllTextAsync("test.js");
            //await pm.CreateContinuousAsync("test", fileStr);
        }
Пример #8
0
 public ReadFromEventStoreBenchmarks()
 {
     _eventStore = EventStoreHelpers.WireupEventStore();
 }
 public WriteToStreamBenchmarks()
 {
     _eventStore = EventStoreHelpers.WireupEventStore();
 }
Пример #10
0
 public PersistenceBenchmarks()
 {
     _eventStore = EventStoreHelpers.WireupEventStore();
 }