22using System . Text ;
33using Confluent . Kafka ;
44using LantanaGroup . Link . Automation . Link . Configuration ;
5+ using LantanaGroup . Link . Shared . Application . Models . Configs ;
56using Newtonsoft . Json . Linq ;
67using RestSharp ;
78
@@ -19,8 +20,7 @@ public class KafkaErrorMonitor : IAsyncDisposable
1920{
2021 private readonly string _kafkaBootstrapServers ;
2122 private readonly string _kafkaRestProxyBase ;
22- private readonly string _kafkaUser ;
23- private readonly string _kafkaPassword ;
23+ private readonly KafkaConnection _kafkaConnection ;
2424
2525 private readonly IAutomationOutput _output ;
2626 private IConsumer < string , string > ? _consumer ;
@@ -76,13 +76,12 @@ private sealed record CapturedKafkaError(string? Key, string Message);
7676 private const int ResourceNormalizedValuePreviewLength = 4000 ;
7777 private const int ResourceNormalizedHeaderPreviewLength = 2000 ;
7878
79- public KafkaErrorMonitor ( IAutomationOutput output , AutomationConfig config )
79+ public KafkaErrorMonitor ( IAutomationOutput output , AutomationConfig config , KafkaConnection kafkaConnection )
8080 {
8181 _output = output ;
82- _kafkaBootstrapServers = config . Kafka . BootstrapServers ;
82+ _kafkaConnection = kafkaConnection ;
83+ _kafkaBootstrapServers = string . Join ( ", " , kafkaConnection . BootstrapServers ) ;
8384 _kafkaRestProxyBase = config . Kafka . RestProxyBaseUrl ;
84- _kafkaUser = config . Kafka . User ;
85- _kafkaPassword = config . Kafka . Password ;
8685 }
8786
8887 /// <summary>
@@ -136,17 +135,12 @@ public async Task InitializeAsync()
136135 SocketTimeoutMs = 5000 ,
137136 } ;
138137
139- // Only enable SASL when credentials are actually configured. The Link services
140- // gate SASL behind KafkaConnection.SaslProtocolEnabled (default false) and the
141- // local/dev/docker brokers use PLAINTEXT. Forcing SaslPlaintext/Plain here with
142- // empty credentials makes librdkafka throw "sasl.username and sasl.password must
143- // be set", which silently disabled dead-letter monitoring for the whole run.
144- if ( ! string . IsNullOrWhiteSpace ( _kafkaUser ) && ! string . IsNullOrWhiteSpace ( _kafkaPassword ) )
138+ if ( _kafkaConnection . SaslProtocolEnabled )
145139 {
146- config . SecurityProtocol = SecurityProtocol . SaslPlaintext ;
147- config . SaslMechanism = SaslMechanism . Plain ;
148- config . SaslUsername = _kafkaUser ;
149- config . SaslPassword = _kafkaPassword ;
140+ config . SecurityProtocol = _kafkaConnection . Protocol ;
141+ config . SaslMechanism = _kafkaConnection . Mechanism ;
142+ config . SaslUsername = _kafkaConnection . SaslUsername ;
143+ config . SaslPassword = _kafkaConnection . SaslPassword ;
150144 }
151145
152146 _consumer = new ConsumerBuilder < string , string > ( config )
0 commit comments