Example #1
0
 public kafkaConfWrapper()
 {
     kafkaProducer          = new kafkaProducerConf();
     kafkaRPC               = new kafkaRPCConf();
     opcSystemName          = "OPC";
     KafkaSchemaRegistryURL = "localhost:8081";
     KafkaServers           = "localhost:9092";
 }
Example #2
0
        public opcKafkaRPC(kafkaRPCConf conf, CachedSchemaRegistryClient schemaRegistry)
        {
            _conf = conf;

            logger   = LogManager.GetLogger(this.GetType().Name);
            _schemas = new opcSchemas();

            // Override default GroupID if name exist
            if (conf.GroupId == "OPC")
            {
                conf.GroupId = conf.opcSystemName;
            }

            // build the consumer, and subscribe it to topic
            _consumer = new ConsumerBuilder <String, GenericRecord>(conf.getConsumerConf())
                        .SetValueDeserializer(new AvroDeserializer <GenericRecord>(schemaRegistry).AsSyncOverAsync())
                        .SetErrorHandler((_, e) => logger.Error($"Error: {e.Reason}"))
                        .Build();
            _consumer.Subscribe(conf.opcSystemName + "-request");

            // build the producer for the responses
            var producer_conf = new ProducerConfig()
            {
                BootstrapServers = conf.BootstrapServers,
                LingerMs         = 5 // low latency response
            };

            _producer = new ProducerBuilder <String, GenericRecord>(producer_conf)
                        .SetValueSerializer(new AvroSerializer <GenericRecord>(schemaRegistry))
                        .SetErrorHandler((_, e) => logger.Error($"Error: {e.Reason}"))
                        .Build();

            if (_conf.enableKafkaRPC)
            {
                logger.Info("Connected to broker: " + _conf.BootstrapServers);
                logger.Info("Request are to be made on topic: " + conf.opcSystemName + "-request");
                logger.Info("Response will be on topic: " + _conf.opcSystemName + "-response");
            }
        }