public VerifiableConsumer(VerifiableConsumerConfig clientConfig) { Config = clientConfig; Config.Conf["enable.auto.commit"] = Config.AutoCommit; Handle = new Consumer <Null, string>(Config.Conf, new NullDeserializer(), new StringDeserializer(Encoding.UTF8)); consumedMsgsAtLastCommit = 0; Dbg($"Created Consumer {Handle.Name} with AutoCommit={Config.AutoCommit}"); }
public VerifiableConsumer(VerifiableConsumerConfig clientConfig) { Config = clientConfig; Config.Conf["enable.auto.commit"] = Config.AutoCommit; var consumerConfig = new ConsumerConfig(Config.Conf.ToDictionary(a => a.Key, a => a.Value.ToString())); consumer = new Consumer <Null, string>(consumerConfig); consumedMsgsAtLastCommit = 0; Dbg($"Created Consumer {consumer.Name} with AutoCommit={Config.AutoCommit}"); }
public VerifiableConsumer(VerifiableConsumerConfig clientConfig) { Config = clientConfig; Config.Conf["enable.auto.commit"] = Config.AutoCommit; var consumerConfig = new ConsumerConfig(Config.Conf.ToDictionary(a => a.Key, a => a.Value.ToString())); consumer = new ConsumerBuilder <Null, string>(consumerConfig) .SetPartitionsAssignedHandler( (_, partitions) => HandleAssign(partitions)) .SetPartitionsRevokedHandler( (_, partitions) => HandleRevoke(partitions)) .SetOffsetsCommittedHandler( (_, offsets) => SendOffsetsCommitted(offsets)) .Build(); consumedMsgsAtLastCommit = 0; Dbg($"Created Consumer {consumer.Name} with AutoCommit={Config.AutoCommit}"); }
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))); } }