Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create topic with additional configuration if present #601

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
init_broker:
@echo command | date
@echo Initializing Kafka broker
docker-compose -f docker-compose.yml up -d
docker compose -f docker-compose.yml up -d
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the makefile, since it was failing to build due to using the wrong command under latest Ubuntu


shutdown_broker:
@echo command | date
@echo Shutting down kafka broker
docker-compose -f docker-compose.yml down
docker compose -f docker-compose.yml down

restore:
dotnet restore KafkaFlow.sln
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public interface IClusterConfigurationBuilder
/// <param name="topicName">The topic name</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>
/// <param name="configs">Additional topic creation configuration values.</param>
/// <returns></returns>
IClusterConfigurationBuilder CreateTopicIfNotExists(
string topicName,
int numberOfPartitions = -1,
short replicationFactor = -1);
short replicationFactor = -1,
Dictionary<string, string> configs = null);
}
1 change: 1 addition & 0 deletions src/KafkaFlow/Clusters/ClusterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public async Task CreateIfNotExistsAsync(IEnumerable<TopicConfiguration> configu
Name = topicConfiguration.Name,
ReplicationFactor = topicConfiguration.Replicas,
NumPartitions = topicConfiguration.Partitions,
Configs = topicConfiguration.Configs,
})
.ToArray();

Expand Down
5 changes: 3 additions & 2 deletions src/KafkaFlow/Configuration/ClusterConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ public IClusterConfigurationBuilder OnStarted(Action<IDependencyResolver> handle
public IClusterConfigurationBuilder CreateTopicIfNotExists(
string topicName,
int numberOfPartitions = -1,
short replicationFactor = -1)
short replicationFactor = -1,
Dictionary<string, string> configs = null)
{
_topicsToCreateIfNotExist.Add(new TopicConfiguration(topicName, numberOfPartitions, replicationFactor));
_topicsToCreateIfNotExist.Add(new TopicConfiguration(topicName, numberOfPartitions, replicationFactor, configs));
return this;
}
}
11 changes: 10 additions & 1 deletion src/KafkaFlow/Configuration/TopicConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace KafkaFlow.Configuration;

/// <summary>
Expand All @@ -11,11 +13,13 @@ public class TopicConfiguration
/// <param name="name">The topic name</param>
/// <param name="partitions">The number of partitions for the topic</param>
/// <param name="replicas">Replication factor for the topic</param>
public TopicConfiguration(string name, int partitions, short replicas)
/// <param name="configs">Additional topic creation configuration values.</param>
public TopicConfiguration(string name, int partitions, short replicas, Dictionary<string, string> configs)
{
this.Name = name;
this.Partitions = partitions;
this.Replicas = replicas;
this.Configs = configs;
}

/// <summary>
Expand All @@ -32,4 +36,9 @@ public TopicConfiguration(string name, int partitions, short replicas)
/// Gets the Topic Replication Factor
/// </summary>
public short Replicas { get; }

/// <summary>
/// Gets the topic creation configuration
/// </summary>
public Dictionary<string, string> Configs { get; }
}
Loading