Example #1
0
 public VerifiableProducer(VerifiableProducerConfig clientConfig)
 {
     Config          = clientConfig;
     Handle          = new Producer <Null, string>(Config.Conf, new NullSerializer(), new StringSerializer(Encoding.UTF8));
     ProduceLock     = new object();
     deliveryHandler = new DeliveryHandler(this);
     Dbg("Created producer " + Handle.Name);
 }
Example #2
0
        public VerifiableProducer(VerifiableProducerConfig clientConfig)
        {
            Config = clientConfig;
            var producerConfig = new ProducerConfig(Config.Conf.ToDictionary(a => a.Key, a => a.Value.ToString()));

            Handle      = new ProducerBuilder <byte[], byte[]>(producerConfig).Build();
            ProduceLock = new object();
            Dbg("Created producer " + Handle.Name);
        }
Example #3
0
        static private VerifiableClient NewClientFromArgs(string[] args)
        {
            VerifiableClientConfig conf = null; // avoid warning
            string mode = "";

            if (args.Length < 1)
            {
                Usage(1, "--consumer or --producer must be specified");
            }
            mode = args[0];
            if (mode.Equals("--producer"))
            {
                conf = new VerifiableProducerConfig();
            }
            else if (mode.Equals("--consumer"))
            {
                conf = new VerifiableConsumerConfig();
            }
            else
            {
                Usage(1, "--consumer or --producer must be the first argument");
            }

            for (var i = 1; i < args.Length; i += 2)
            {
                var    key = args[i];
                string val = null;
                if (i + 1 < args.Length)
                {
                    val = args[i + 1];
                }

                // It is helpful to see the passed arguments from system test logs
                Console.Error.WriteLine($"{mode} Arg: {key} {val}");
                switch (key)
                {
                /* Generic options */
                case "--topic":
                    AssertValue(mode, key, val);
                    conf.Topic = val;
                    break;

                case "--broker-list":
                    AssertValue(mode, key, val);
                    conf.Conf["bootstrap.servers"] = val;
                    break;

                case "--max-messages":
                    AssertValue(mode, key, val);
                    conf.MaxMsgs = int.Parse(val);
                    break;

                case "--debug":
                    AssertValue(mode, key, val);
                    conf.Conf["debug"] = val;
                    break;

                case "--property":
                    AssertValue(mode, key, val);
                    foreach (var kv in val.Split(','))
                    {
                        var kva = kv.Split('=');
                        if (kva.Length != 2)
                        {
                            Usage(1, $"Invalid property: {kv}");
                        }

                        conf.Conf[kva[0]] = kva[1];
                    }
                    break;

                // Producer options
                case "--throughput":
                    AssertValue(mode, key, val);
                    AssertProducer(mode, key);
                    ((VerifiableProducerConfig)conf).MsgRate = double.Parse(val);
                    break;

                case "--value-prefix":
                    AssertValue(mode, key, val);
                    AssertProducer(mode, key);
                    ((VerifiableProducerConfig)conf).ValuePrefix = val + ".";
                    break;

                case "--acks":
                    AssertValue(mode, key, val);
                    AssertProducer(mode, key);
                    conf.Conf["acks"] = val;
                    break;

                case "--producer.config":
                    // Ignored
                    break;

                // Consumer options
                case "--group-id":
                    AssertValue(mode, key, val);
                    AssertConsumer(mode, key);
                    conf.Conf["group.id"] = val;
                    break;

                case "--session-timeout":
                    AssertValue(mode, key, val);
                    AssertConsumer(mode, key);
                    conf.Conf["session.timeout.ms"] = int.Parse(val);
                    break;

                case "--enable-autocommit":
                    AssertConsumer(mode, key);
                    i -= 1;     // dont consume value part
                    ((VerifiableConsumerConfig)conf).AutoCommit = true;
                    break;

                case "--assignment-strategy":
                    AssertValue(mode, key, val);
                    AssertConsumer(mode, key);
                    conf.Conf["partition.assignment.strategy"] = JavaAssignmentStrategyParse(val);
                    break;

                case "--consumer.config":
                    // Ignored
                    break;

                default:
                    Usage(1, $"Invalid option: {key} {val}");
                    break;
                }
            }

            if (conf.Topic.Length == 0)
            {
                Usage(1, "Missing --topic ..");
            }

            Console.Error.WriteLine($"Running {mode} using librdkafka {Confluent.Kafka.Library.VersionString} ({Confluent.Kafka.Library.Version:x})");
            if (mode.Equals("--producer"))
            {
                return(new VerifiableProducer(((VerifiableProducerConfig)conf)));
            }
            else
            {
                return(new VerifiableConsumer(((VerifiableConsumerConfig)conf)));
            }
        }