// based on https://github.com/confluentinc/examples/blob/6.1.1-post/clients/cloud/csharp/Program.cs static async Task Main(string[] args) { var topic = args.Length > 0 ? args[0] : "sample-topic"; var config = Config.Create(); await TopicHelpers.TryDeleteTopic(topic, config); await ConsumeAgainstNonExistentTopic(topic, config); await ConsumeAndProduceMessages(topic, config); Console.WriteLine($"Shut down complete"); }
// based on https://github.com/confluentinc/examples/blob/6.1.1-post/clients/cloud/csharp/Program.cs static async Task Main(string[] args) { var topic = args.Length > 0 ? args[0] : "sample-topic"; var config = Config.Create(); await TopicHelpers.TryDeleteTopic(topic, config); await TopicHelpers.TryCreateTopic( topic, numPartitions : 3, replicationFactor : 1, config); await ConsumeAndProduceMessages(topic, config); Console.WriteLine($"Shut down complete"); }
private static async Task ConsumeAgainstNonExistentTopic(string topic, ClientConfig config) { using var consumer = Consumer.Create(enableAutoCommit: true, topic, consumerName: "FailingConsumer 1"); Console.WriteLine($"Manually consuming non-existent topic..."); // On Kafka.Confluent 1.5.3 this will throw, so success will be false // That creates an exception Span // On other versions, this _won't_ throw, and _won't_ create a span var success = consumer.Consume(retries: 1, timeoutMilliSeconds: 300); Console.WriteLine($"Manual consume complete, success {success}"); // Create the topic and try again await TopicHelpers.TryCreateTopic(topic, numPartitions : 3, replicationFactor : 1, config); Console.WriteLine($"Manually consuming topic..."); // manually try and consume. Should _not_ generate any spans, as nothing to consume // but on 1.5.3 this may generate some error spans success = consumer.Consume(retries: 5, timeoutMilliSeconds: 300); Console.WriteLine($"Manual consume finished, success {success}"); }