Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] Item item)
        {
            var counter = _receivedMessageounter.CountOperation("counter", "operation(s)", true, LogEventLevel.Information);

            counter.Increment();
            var random      = new Random();
            var randomValue = random.Next(0, 100);

            _logger.LogInformation($"Random Value is {randomValue}");

            string serializeItem = JsonConvert.SerializeObject(item);

            using (var producer = new ProducerBuilder <Null, string>(_producerConfig).Build())
            {
                await producer.ProduceAsync(_topic, new Message <Null, string> {
                    Value = serializeItem
                });

                producer.Flush(TimeSpan.FromSeconds(10));
                _logger.LogInformation("Item Post Successfull at: {time}", DateTimeOffset.Now);
                return(Ok(true));
            }
        }