public CounterKafkaService(CafeDatabaseSettings cafeDatabaseSettings, CafeKafkaSettings cafeKafkaSettings)
        {
            try
            {
                _consumerConfig = KafkaConfig.CreateConsumerConfig(cafeKafkaSettings);

                _producerConfig = KafkaConfig.CreateProducerConfig(cafeKafkaSettings);

                Console.WriteLine(DateTime.Now + " - Read Kafka Bootstrap: " + cafeKafkaSettings.BootstrapServers);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in kafka settings: " + ex);
            }

            try
            {
                var client   = new MongoClient(cafeDatabaseSettings.ConnectionString);
                var database = client.GetDatabase(cafeDatabaseSettings.DatabaseName);
                _orderRepository = database.GetCollection <Order>(cafeDatabaseSettings.OrdersCollectionName);

                Console.WriteLine(DateTime.Now + " - Read MongoDB Connection String: " + cafeDatabaseSettings.ConnectionString);
                Console.WriteLine(DateTime.Now + " - Read MongoDB DB Name: " + cafeDatabaseSettings.DatabaseName);
                Console.WriteLine(DateTime.Now + " - Read MongoDB Collection Name: " + cafeDatabaseSettings.OrdersCollectionName);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in mongodb settings: " + ex);
            }
        }
        public KitchenKafkaService(CafeKafkaSettings cafeKafkaSettings)
        {
            _kitchen = new Kitchen();
            try
            {
                _consumerConfig = KafkaConfig.CreateConsumerConfig(cafeKafkaSettings);

                _producerConfig = KafkaConfig.CreateProducerConfig(cafeKafkaSettings);

                Console.WriteLine(DateTime.Now + " - Read Kafka Bootstrap: " + cafeKafkaSettings.BootstrapServers);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in kafka settings: " + ex);
            }
        }
        public InventoryKafkaService(CafeKafkaSettings cafeKafkaSettings)
        {
            _stockRoom = new StockRoom();
            try
            {
                _consumerConfig = KafkaConfig.CreateConsumerConfig(cafeKafkaSettings);

                _producerConfig = KafkaConfig.CreateProducerConfig(cafeKafkaSettings);

                Console.WriteLine("Read Kafka Bootstrap: " + cafeKafkaSettings.BootstrapServers);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in kafka settings: " + ex);
            }
        }
Ejemplo n.º 4
0
        public BaristaKafkaService(CafeKafkaSettings cafeKafkaSettings)
        {
            _barista = new Barista();
            try
            {
                _consumerConfig = KafkaConfig.CreateConsumerConfig(cafeKafkaSettings);

                _producerConfig = KafkaConfig.CreateProducerConfig(cafeKafkaSettings);

                Console.WriteLine("Read Kafka Bootstrap: " + cafeKafkaSettings.BootstrapServers);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in kafka settings: " + ex);
            }
        }
Ejemplo n.º 5
0
        public async Task Get(CancellationToken cancellationToken)
        {
            var response = Response;

            response.StatusCode = 200;
            response.Headers.Add("Content-Type", "text/event-stream");
            response.Headers.Add("Cache-Control", "no-cache");
            response.Headers.Add("Connection", "keep-alive");

            String kafkaBootstrap    = Environment.GetEnvironmentVariable("DOTNET_CAFE_KAFKA_BOOTSTRAP") ?? "127.0.0.1:9099";
            var    cafeKafkaSettings = new CafeKafkaSettings(kafkaBootstrap);
            var    consumerConfig    = KafkaConfig.CreateConsumerConfig(cafeKafkaSettings);

            Task.Run(() => { ConsumeKafka(consumerConfig, cancellationToken); });

            await response.Body.FlushAsync();

            while (!cancellationToken.IsCancellationRequested)
            {
                while (queue.TryDequeue(out var message))
                {
                    OrderUpEvent    item            = JsonSerializer.Deserialize <OrderUpEvent>(message);
                    DashboardUpdate dashboardUpdate = new DashboardUpdate(item);

                    var serializerOptions = new JsonSerializerOptions
                    {
                        Converters       = { new JsonStringEnumConverter() },
                        IgnoreNullValues = true
                    };

                    String dashboardUpdateJson = JsonSerializer.Serialize(dashboardUpdate, serializerOptions);
                    await response.WriteAsync($"data:{dashboardUpdateJson} \n\n");

                    await response.Body.FlushAsync();
                }

                await Task.Delay(1 * 1000);
            }
        }