-
Notifications
You must be signed in to change notification settings - Fork 348
/
KafkaConsumerSettings.cs
67 lines (56 loc) · 1.88 KB
/
KafkaConsumerSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using Confluent.Kafka;
namespace Aspire.Confluent.Kafka;
/// <summary>
/// Provides the client configuration settings for connecting to a Kafka message broker to consume messages.
/// </summary>
public sealed class KafkaConsumerSettings
{
/// <summary>
/// Gets or sets the connection string of the Kafka server to connect to.
/// </summary>
public string? ConnectionString { get; set; }
/// <summary>
/// Gets the configuration settings for the Kafka consumer.
/// </summary>
public ConsumerConfig Config { get; } = new ConsumerConfig();
/// <summary>
/// Gets or sets a boolean value that indicates whether the OpenTelemetry metrics are enabled or not.
/// </summary>
/// <value>
/// The default value is <see langword="false" />.
/// </value>
public bool DisableMetrics { get; set; }
/// <summary>
/// Gets or sets a boolean value that indicates whether the Kafka health check is disabled or not.
/// </summary>
/// <value>
/// The default value is <see langword="false" />.
/// </value>
public bool DisableHealthChecks { get; set; }
internal void Consolidate()
{
Debug.Assert(Config is not null);
if (ConnectionString is not null)
{
Config.BootstrapServers = ConnectionString;
}
if (!DisableMetrics)
{
Config.StatisticsIntervalMs ??= 1000;
}
}
internal void Validate()
{
if (Config.BootstrapServers is null)
{
throw new InvalidOperationException("No bootstrap servers configured.");
}
if (Config.GroupId is null)
{
throw new InvalidOperationException("No group id configured.");
}
}
}