Пример #1
0
 public Task Handle(PlayerInventoryChangedEvent evnt)
 {
     // TODO: Make fully async and using proper DI
     using (var dbContext = ReadModelDbContext.CreateContext(_configuration))
     {
         var entityRepository = new EntityRepository(dbContext);
         entityRepository.Enrich(evnt.InventoryChange);
     }
     return(Task.CompletedTask);
 }
Пример #2
0
        public async Task HandleEvent <TEvent>(TEvent evnt) where TEvent : IEvent
        {
            using (var dbContext = ReadModelDbContext.CreateContext(_configuration))
            {
                var dispatcher = new EventDispatcher(dbContext, _logger);
                await dispatcher.Handle(evnt);

                UpdateState(dbContext, evnt);
                try
                {
                    await dbContext.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Could not commit changes from dispatcher!");
                }
            }
        }
Пример #3
0
 public void Run()
 {
     using (var dbContext = ReadModelDbContext.CreateContext(_configuration))
     {
         var initialState = dbContext.ConsumerStates
                            .Where(s => s.GroupId == _configurationModel.Kafka.GroupId)
                            .ToList();
         if (initialState.Count() > 0)
         {
             // We have already rehydrated this context; lets continue where we left off
             var subscriptions = initialState
                                 .Select(s => new TopicPartitionOffset(s.Topic, s.Partition, s.Offset + 1))
                                 .ToArray();
             _logger.Information($"Found existing context state, subscribing to: ${string.Join(", ", subscriptions.Select(s => s.ToString()))}");
             _consumer.Subscribe(subscriptions);
         }
         else
         {
             // This context needs rehydration; start from beginning
             _logger.Information("No existing state found for context; rehydrating..");
             _consumer.Subscribe(new TopicPartitionOffset(KafkaTopics.EVENTS, 0, 0));
         }
     }
 }