Skip to content

Commit

Permalink
consumer group per consumer type #GCPActive (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad authored Nov 27, 2023
1 parent 07c6c2a commit 916bc9c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ public class AdminSettings
/// The list of topics the admin client is responsible for ensuring that exist
/// </summary>
public List<string> TopicList { get; set; } = new List<string>();

/// <summary>
/// The retention time in days for the topics
/// </summary>
public int RetentionTime { get; set; } = 7;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected KafkaConsumerBase(

var consumerConfig = new ConsumerConfig(config.ConsumerSettings)
{
GroupId = settings.Value.Consumer.GroupId,
GroupId = $"{settings.Value.Consumer.GroupId}-{GetType().Name.ToLower()}",
EnableAutoCommit = false,
EnableAutoOffsetStore = false,
AutoOffsetReset = AutoOffsetReset.Earliest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ private void EnsureTopicsExist()
{
Name = topic,
NumPartitions = TopicSpecification.NumPartitions,
ReplicationFactor = TopicSpecification.ReplicationFactor
ReplicationFactor = TopicSpecification.ReplicationFactor,
Configs = TopicSpecification.Configs
}
}).Wait();
_logger.LogInformation("// KafkaProducer // EnsureTopicsExists // Topic '{Topic}' created successfully.", topic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ public SharedClientConfig(Configuration.KafkaSettings settings)
consumerConfig.SaslUsername = settings.Consumer.SaslUsername;
consumerConfig.SaslPassword = settings.Consumer.SaslPassword;

string retentionTime = settings.Admin.RetentionTime < 0 ? "-1" : TimeSpan.FromDays(settings.Admin.RetentionTime).TotalMilliseconds.ToString();
topicSpec.NumPartitions = 6;
topicSpec.ReplicationFactor = 3;
topicSpec.Configs = new Dictionary<string, string>()
{
{ "retention.ms", retentionTime },
{ "cleanup.policy", "delete" }
};
}

AdminClientSettings = adminConfig;
Expand Down

This file was deleted.

0 comments on commit 916bc9c

Please sign in to comment.