33
33
import org .springframework .boot .context .properties .ConfigurationProperties ;
34
34
import org .springframework .core .io .Resource ;
35
35
import org .springframework .kafka .listener .AbstractMessageListenerContainer .AckMode ;
36
+ import org .springframework .util .CollectionUtils ;
36
37
37
38
/**
38
39
* Configuration properties for Spring for Apache Kafka.
47
48
@ ConfigurationProperties (prefix = "spring.kafka" )
48
49
public class KafkaProperties {
49
50
50
- private final Consumer consumer = new Consumer ();
51
-
52
- private final Producer producer = new Producer ();
53
-
54
- private final Listener listener = new Listener ();
55
-
56
- private final Template template = new Template ();
57
-
58
- private final Ssl ssl = new Ssl ();
59
-
60
- // Apache Kafka Common Properties
61
-
62
51
/**
63
52
* Comma-delimited list of host:port pairs to use for establishing the initial
64
53
* connection to the Kafka cluster.
@@ -76,25 +65,15 @@ public class KafkaProperties {
76
65
*/
77
66
private Map <String , String > properties = new HashMap <String , String >();
78
67
79
- public Consumer getConsumer () {
80
- return this .consumer ;
81
- }
68
+ private final Consumer consumer = new Consumer ();
82
69
83
- public Producer getProducer () {
84
- return this .producer ;
85
- }
70
+ private final Producer producer = new Producer ();
86
71
87
- public Listener getListener () {
88
- return this .listener ;
89
- }
72
+ private final Listener listener = new Listener ();
90
73
91
- public Ssl getSsl () {
92
- return this .ssl ;
93
- }
74
+ private final Ssl ssl = new Ssl ();
94
75
95
- public Template getTemplate () {
96
- return this .template ;
97
- }
76
+ private final Template template = new Template ();
98
77
99
78
public List <String > getBootstrapServers () {
100
79
return this .bootstrapServers ;
@@ -120,6 +99,26 @@ public void setProperties(Map<String, String> properties) {
120
99
this .properties = properties ;
121
100
}
122
101
102
+ public Consumer getConsumer () {
103
+ return this .consumer ;
104
+ }
105
+
106
+ public Producer getProducer () {
107
+ return this .producer ;
108
+ }
109
+
110
+ public Listener getListener () {
111
+ return this .listener ;
112
+ }
113
+
114
+ public Ssl getSsl () {
115
+ return this .ssl ;
116
+ }
117
+
118
+ public Template getTemplate () {
119
+ return this .template ;
120
+ }
121
+
123
122
private Map <String , Object > buildCommonProperties () {
124
123
Map <String , Object > properties = new HashMap <String , Object >();
125
124
if (this .bootstrapServers != null ) {
@@ -148,7 +147,7 @@ private Map<String, Object> buildCommonProperties() {
148
147
properties .put (SslConfigs .SSL_TRUSTSTORE_PASSWORD_CONFIG ,
149
148
this .ssl .getTruststorePassword ());
150
149
}
151
- if (this . properties != null && this .properties . size () > 0 ) {
150
+ if (! CollectionUtils . isEmpty ( this .properties ) ) {
152
151
properties .putAll (this .properties );
153
152
}
154
153
return properties ;
@@ -163,9 +162,9 @@ private Map<String, Object> buildCommonProperties() {
163
162
* instance
164
163
*/
165
164
public Map <String , Object > buildConsumerProperties () {
166
- Map <String , Object > props = buildCommonProperties ();
167
- props .putAll (this .consumer .buildProperties ());
168
- return props ;
165
+ Map <String , Object > properties = buildCommonProperties ();
166
+ properties .putAll (this .consumer .buildProperties ());
167
+ return properties ;
169
168
}
170
169
171
170
/**
@@ -177,9 +176,9 @@ public Map<String, Object> buildConsumerProperties() {
177
176
* instance
178
177
*/
179
178
public Map <String , Object > buildProducerProperties () {
180
- Map <String , Object > props = buildCommonProperties ();
181
- props .putAll (this .producer .buildProperties ());
182
- return props ;
179
+ Map <String , Object > properties = buildCommonProperties ();
180
+ properties .putAll (this .producer .buildProperties ());
181
+ return properties ;
183
182
}
184
183
185
184
private static String resourceToPath (Resource resource ) {
@@ -425,7 +424,8 @@ public Map<String, Object> buildProperties() {
425
424
this .valueDeserializer );
426
425
}
427
426
if (this .maxPollRecords != null ) {
428
- properties .put (ConsumerConfig .MAX_POLL_RECORDS_CONFIG , this .maxPollRecords );
427
+ properties .put (ConsumerConfig .MAX_POLL_RECORDS_CONFIG ,
428
+ this .maxPollRecords );
429
429
}
430
430
return properties ;
431
431
}
0 commit comments