示例#1
0
        public void Dispose()
        {
            var adminClient = new AdminClientBuilder(new AdminClientConfig {
                BootstrapServers = this.bootstrapServers
            }).Build();

            adminClient.DeleteTopicsAsync(new List <string> {
                Name
            }).Wait();
            adminClient.Dispose();
        }
        public async Task <IActionResult> CreatePartitions()
        {
            using (IAdminClient adminClient = new Confluent.Kafka.AdminClientBuilder(_kafkaOptions.AdminClientConfig).Build())
            {
                await adminClient.CreateTopicsAsync(new TopicSpecification[] {
                    new TopicSpecification {
                        Name = "Log", NumPartitions = 24
                    },
                    new TopicSpecification {
                        Name = "Order", NumPartitions = 24
                    },
                });
            }

            return(Ok());
        }
示例#3
0
        public TemporaryTopic(string bootstrapServers, int numPartitions)
        {
            this.bootstrapServers = bootstrapServers;
            this.Name             = "dotnet_test_" + Guid.NewGuid().ToString();

            var adminClient = new AdminClientBuilder(new AdminClientConfig {
                BootstrapServers = bootstrapServers
            }).Build();

            adminClient.CreateTopicsAsync(new List <TopicSpecification> {
                new TopicSpecification {
                    Name = Name, NumPartitions = numPartitions, ReplicationFactor = 1
                }
            }).Wait();
            adminClient.Dispose();
        }