Beispiel #1
0
        public string GetQueryProtocol()
        {
            string             message;
            KafkaProtocolModel protocol = new KafkaProtocolModel();

            protocol.Head.Action  = "QUERY";
            protocol.Head.Version = "1";

            message = JsonSerializer.Serialize(protocol);

            return(message);
        }
Beispiel #2
0
        internal string GetAddNewProtocol(CarViewModel car)
        {
            string             message;
            KafkaProtocolModel protocol = new KafkaProtocolModel();

            protocol.Head.Action  = "ADD_CAR";
            protocol.Head.Version = "1";

            protocol.Data.Add(new KpCarModel
            {
                CarBrand   = car.CarBrand,
                CarModel   = car.CarModel,
                EngineType = car.EngineType
            });

            message = JsonSerializer.Serialize(protocol);

            return(message);
        }
Beispiel #3
0
        private async Task ProcessQuery(KafkaProducerService producerService)
        {
            var allCars = await this.manager.GetCarsAsync();

            List <KpCarModel> cars = this.adaptor.MappCarViewModel(allCars);

            KafkaProtocolModel kafkaProtocol = new KafkaProtocolModel
            {
                Data = cars,
                Head = new KpHeapModel
                {
                    Action  = "Result",
                    Version = "1"
                }
            };

            string jsonString = JsonSerializer.Serialize(kafkaProtocol);

            await producerService.ProduceMessageAsync(jsonString);
        }
        public async Task ProccessMessage(KafkaOptions kafkaOptions, IServiceScope serviceScope, string message)
        {
            IKafkaServiceFactory kafkaFactory = serviceScope.ServiceProvider
                                                .GetRequiredService <IKafkaServiceFactory>();

            IFactory factory = serviceScope.ServiceProvider
                               .GetRequiredService <IFactory>();

            this.manager = new PersonManager(factory);
            this.adaptor = factory.GetAdaptor();

            KafkaProducerService producerService = kafkaFactory.GetProducerService
                                                   (
                kafkaOptions.Settings,
                kafkaOptions.Producers[0]
                                                   );

            if (int.TryParse(message, out int id))
            {
                KafkaProtocolModel kafkaProtocol = this.GetProtocol(message);

                switch (kafkaProtocol.Head.Action)
                {
                case "QUERY":
                    await this.ProcessQuery(producerService);

                    break;

                case "ADD_PERSON":
                    await this.ProcessAddPerson(kafkaProtocol.Data[0], producerService);

                    break;
                }
            }
            else
            {
                var carID = int.Parse(message);
                await this.RemoveCar(carID);
            }
        }
Beispiel #5
0
        public List <CarViewModel> GetCars(string msg)
        {
            KafkaProtocolModel kafkaProtocol = this.GetProtocol(msg);

            return(Mapp(kafkaProtocol.Data));
        }