From 6ede5c783eebfab937c2bc31e2b848e56680a0f2 Mon Sep 17 00:00:00 2001 From: Robert Coltheart Date: Thu, 11 Apr 2024 08:38:12 +1000 Subject: [PATCH] feat: allow use of cluster defined values for topic creation --- .../Configuration/IClusterConfigurationBuilder.cs | 8 ++++---- .../Configuration/ClusterConfigurationBuilder.cs | 4 ++-- tests/KafkaFlow.IntegrationTests/Core/Bootstrapper.cs | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/KafkaFlow.Abstractions/Configuration/IClusterConfigurationBuilder.cs b/src/KafkaFlow.Abstractions/Configuration/IClusterConfigurationBuilder.cs index 494e0d301..2c6968baa 100644 --- a/src/KafkaFlow.Abstractions/Configuration/IClusterConfigurationBuilder.cs +++ b/src/KafkaFlow.Abstractions/Configuration/IClusterConfigurationBuilder.cs @@ -75,11 +75,11 @@ public interface IClusterConfigurationBuilder /// Adds a Topic to the Cluster /// /// The topic name - /// The number of Topic partitions - /// The Topic replication factor + /// The number of Topic partitions. Default is to use the cluster-defined partitions. + /// The Topic replication factor. Default is to use the cluster-defined replication factor. /// IClusterConfigurationBuilder CreateTopicIfNotExists( string topicName, - int numberOfPartitions, - short replicationFactor); + int numberOfPartitions = -1, + short replicationFactor = -1); } diff --git a/src/KafkaFlow/Configuration/ClusterConfigurationBuilder.cs b/src/KafkaFlow/Configuration/ClusterConfigurationBuilder.cs index 6585032b3..cd85129ef 100644 --- a/src/KafkaFlow/Configuration/ClusterConfigurationBuilder.cs +++ b/src/KafkaFlow/Configuration/ClusterConfigurationBuilder.cs @@ -110,8 +110,8 @@ public IClusterConfigurationBuilder OnStarted(Action handle public IClusterConfigurationBuilder CreateTopicIfNotExists( string topicName, - int numberOfPartitions, - short replicationFactor) + int numberOfPartitions = -1, + short replicationFactor = -1) { _topicsToCreateIfNotExist.Add(new TopicConfiguration(topicName, numberOfPartitions, replicationFactor)); return this; diff --git a/tests/KafkaFlow.IntegrationTests/Core/Bootstrapper.cs b/tests/KafkaFlow.IntegrationTests/Core/Bootstrapper.cs index 272df2b19..5e317cc8e 100644 --- a/tests/KafkaFlow.IntegrationTests/Core/Bootstrapper.cs +++ b/tests/KafkaFlow.IntegrationTests/Core/Bootstrapper.cs @@ -42,6 +42,7 @@ internal static class Bootstrapper private const string ProtobufGzipTopicName2 = "test-protobuf-gzip-2"; private const string AvroTopicName = "test-avro"; private const string NullTopicName = "test-null"; + private const string DefaultParamsTopicName = "test-default-params"; private static readonly Lazy s_lazyProvider = new(SetupProvider); @@ -202,6 +203,7 @@ private static void SetupServices(HostBuilderContext context, IServiceCollection .CreateTopicIfNotExists(ProtobufGzipTopicName, 2, 1) .CreateTopicIfNotExists(ProtobufGzipTopicName2, 2, 1) .CreateTopicIfNotExists(NullTopicName, 1, 1) + .CreateTopicIfNotExists(DefaultParamsTopicName) .AddConsumer( consumer => consumer .Topic(ProtobufTopicName)