Skip to content

Commit

Permalink
feat: allow use of cluster defined values for topic creation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcoltheart committed Apr 10, 2024
1 parent 188b21d commit 652b013
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public interface IClusterConfigurationBuilder
/// Adds a Topic to the Cluster
/// </summary>
/// <param name="topicName">The topic name</param>
/// <param name="numberOfPartitions">The number of Topic partitions</param>
/// <param name="replicationFactor">The Topic replication factor</param>
/// <param name="numberOfPartitions">The number of Topic partitions. Default is to use the cluster-defined partitions.</param>
/// <param name="replicationFactor">The Topic replication factor. Default is to use the cluster-defined replication factor.</param>
/// <returns></returns>
IClusterConfigurationBuilder CreateTopicIfNotExists(
string topicName,
int numberOfPartitions,
short replicationFactor);
int numberOfPartitions = -1,
short replicationFactor = -1);
}
4 changes: 2 additions & 2 deletions src/KafkaFlow/Configuration/ClusterConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public IClusterConfigurationBuilder OnStarted(Action<IDependencyResolver> 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;
Expand Down
2 changes: 2 additions & 0 deletions tests/KafkaFlow.IntegrationTests/Core/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IServiceProvider> s_lazyProvider = new(SetupProvider);

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 652b013

Please sign in to comment.