21
21
import java .util .Map ;
22
22
import java .util .Properties ;
23
23
import java .util .stream .Collectors ;
24
+ import java .util .stream .Stream ;
24
25
25
26
public class KafkaConfig {
26
27
private static String bootstrapServersConfig ;
@@ -33,41 +34,36 @@ public class KafkaConfig {
33
34
.standard ()
34
35
.build ();
35
36
36
- private static final String DEFAULT_BOOTSTRAP_SERVERS =
37
- "b-1.qaemodbpocmsk.q4panq.c10.kafka.us-east-1.amazonaws.com:9092," +
38
- "b-2.qaemodbpocmsk.q4panq.c10.kafka.us-east-1.amazonaws.com:9092" ;
39
-
40
37
41
38
static {
42
39
try {
43
40
final String UNIVERSE = getUniverseFromEnv ();
44
41
// Load configurations from SSM during static initialization
42
+ String basePath = "/" + UNIVERSE + "/emodb/kafka/" ;
43
+ // Load configurations from SSM during static initialization
45
44
Map <String , String > parameterValues = getParameterValues (
46
- Arrays .asList (
47
- "/" + UNIVERSE + "/emodb/kafka/batchSize" ,
48
- "/" + UNIVERSE + "/emodb/kafka/retries" ,
49
- "/" + UNIVERSE + "/emodb/kafka/lingerMs" ,
50
- "/" + UNIVERSE + "/emodb/kafka/bootstrapServers"
51
- )
45
+ Stream .of ("batchSize" , "retries" , "lingerMs" , "bootstrapServers" )
46
+ .map (param -> basePath + param )
47
+ .collect (Collectors .toList ())
52
48
);
53
49
54
50
// Set configurations with fallback to defaults if not present
55
51
// Sets the batch size for Kafka producer, which controls the amount of data to batch before sending.
56
- batchSizeConfig = parameterValues .getOrDefault ("/" + UNIVERSE + "/emodb/kafka/ batchSize" , "16384" );
52
+ batchSizeConfig = parameterValues .getOrDefault (basePath + " batchSize" , "16384" );
57
53
58
54
// Sets the number of retry attempts for failed Kafka message sends.
59
- retriesConfig = parameterValues .getOrDefault ("/" + UNIVERSE + "/emodb/kafka/ retries" , "3" );
55
+ retriesConfig = parameterValues .getOrDefault (basePath + " retries" , "3" );
60
56
61
57
// Sets the number of milliseconds a producer is willing to wait before sending a batch out
62
- lingerMsConfig = parameterValues .getOrDefault ("/" + UNIVERSE + "/emodb/kafka/ lingerMs" , "1" );
58
+ lingerMsConfig = parameterValues .getOrDefault (basePath + " lingerMs" , "1" );
63
59
64
60
// Configures the Kafka broker addresses for producer connections.
65
- bootstrapServersConfig = parameterValues .getOrDefault ( "/" + UNIVERSE + "/emodb/kafka/ bootstrapServers", DEFAULT_BOOTSTRAP_SERVERS );
61
+ bootstrapServersConfig = parameterValues .get ( basePath + " bootstrapServers" );
66
62
67
- logger . info ( "Kafka configurations loaded successfully from SSM." );
68
- } catch ( AmazonServiceException e ) {
69
- logger . error ( "Failed to load configurations from SSM. Using default values." , e );
70
- throw e ;
63
+ // Log the kafka configurations loaded from SSM
64
+ logger . info ( "Kafka configurations loaded from SSM: batchSize={}, retries={}, lingerMs={}, bootstrapServers={}" ,
65
+ batchSizeConfig , retriesConfig , lingerMsConfig ,
66
+ bootstrapServersConfig != null ? bootstrapServersConfig : "Not configured (null)" ) ;
71
67
}
72
68
catch (Exception e ) {
73
69
logger .error ("Unexpected error occurred while loading configurations from SSM. Using default values." , e );
0 commit comments