Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation($"Starting EventManager service. Consuming to the following topics [{string.Join(", ", _configuration.Topics)}]");

            await Task.Run(() =>
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    //_consumer.Consume(stoppingToken);
                    string contactString   = _consumer.ConsumeReadMessage(stoppingToken);
                    Contact contactTostore = JsonConvert.DeserializeObject <Contact>(contactString);

                    try
                    {
                        using (TestEntityFContext context = new TestEntityFContext())
                        {
                            context.Contact.Add(contactTostore);
                            context.SaveChanges();
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }, stoppingToken);
        }