public opcProducerTest()
        {
            var log        = new NLog.Config.LoggingConfiguration();
            var logconsole = new NLog.Targets.ColoredConsoleTarget("logconsole");

            // Rules for mapping loggers to targets
            log.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            // Apply config
            NLog.LogManager.Configuration = log;

            kafkaProducerConf conf = new kafkaProducerConf()
            {
                MessageSendMaxRetries     = 100,
                BatchNumMessages          = 23,
                QueueBufferingMaxKbytes   = 100,
                QueueBufferingMaxMessages = 32,
                MessageTimeoutMs          = 10000,
                LingerMs = 200
            };

            // schema registry
            var registry = new CachedSchemaRegistryClient(new SchemaRegistryConfig()
            {
                Url = "localhost:8081",
                ValueSubjectNameStrategy = SubjectNameStrategy.TopicRecord
            });

            kafka = new opcKafkaProducer(conf, registry);

            schemas = new opcSchemas();
        }
Exemplo n.º 2
0
        public opcKafkaRPCTest()
        {
            var log        = new NLog.Config.LoggingConfiguration();
            var logconsole = new NLog.Targets.ColoredConsoleTarget("logconsole");

            // Rules for mapping loggers to targets
            log.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            // Apply config
            NLog.LogManager.Configuration = log;

            // schema registry
            registry = new CachedSchemaRegistryClient(new SchemaRegistryConfig()
            {
                Url = "localhost:8081",
                ValueSubjectNameStrategy = SubjectNameStrategy.TopicRecord
            });
            // default configuration
            rpc = new opcKafkaRPC(new kafkaRPCConf(), registry);

            cancel = new CancellationTokenSource();

            schemas = new opcSchemas();

            producer = new ProducerBuilder <String, GenericRecord>(new kafkaProducerConf().getProducerConf())
                       .SetValueSerializer(new AvroSerializer <GenericRecord>(registry))
                       .Build();

            req = new GenericRecord(schemas.rpcRequest);
            req.Add("method", "write");
            req.Add("params", new string[] { "ciao", "bella" });
            req.Add("id", 89);

            var cnf = new kafkaRPCConf().getConsumerConf();

            cnf.AutoOffsetReset = AutoOffsetReset.Earliest;

            // this is necessary otherwise fail because of rebalancing, send messages to dead consumer
            cnf.GroupId = "test-never-give-this-id-" + DateTime.Now.Millisecond.ToString();
            Console.WriteLine("using group id: " + "test-never-give-this-id-" + DateTime.Now.Millisecond.ToString());

            consumer = new ConsumerBuilder <String, GenericRecord>(cnf)
                       .SetValueDeserializer(new AvroDeserializer <GenericRecord>(registry).AsSyncOverAsync())
                       .Build();

            consumer.Subscribe("OPC-response");
        }