private void PrepareTopic(IAdminClient adminClient, string topic) { var metadata = adminClient.GetMetadata(topic, TimeSpan.FromSeconds(20)); var partitionCount = metadata.Topics.First().Partitions.Count; if (partitionCount == 0) { adminClient.CreateTopicsAsync(new[] { new TopicSpecification { NumPartitions = _options.TopicPartitionCount, Name = topic, ReplicationFactor = 1 } }).GetAwaiter().GetResult(); } else { if (partitionCount < _options.TopicPartitionCount) { adminClient.CreatePartitionsAsync(new[] { new PartitionsSpecification { Topic = topic, IncreaseTo = _options.TopicPartitionCount } }).GetAwaiter().GetResult(); } } }
public async Task ChangePartitionCountAsync(string topic, int partitionCount) => await _innerClient.CreatePartitionsAsync(new[] { new PartitionsSpecification { Topic = topic, IncreaseTo = partitionCount } });