Exemple #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);
        }
        public WeatherForecastController(ILogger <WeatherForecastController> logger, KafkaProducer producer
                                         , TestEntityFContext dbContext

                                         )
        {
            _logger   = logger;
            _producer = producer;
        }
        public async void NotificationMessage(Message snsMessage)
        {
            Contact contactTostore = JsonConvert.DeserializeObject <Contact>(snsMessage.MessageText);

            using (TestEntityFContext context = new TestEntityFContext())
            {
                contactTostore.Email = "AWS2:" + contactTostore.Email;
                context.Contact.Add(contactTostore);
                await context.SaveChangesAsync();
            }
        }