|
2 | 2 |
|
3 | 3 | import java.util.Properties; |
4 | 4 |
|
5 | | -import static org.apache.kafka.clients.CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG; |
6 | 5 | import static org.apache.kafka.clients.CommonClientConfigs.REQUEST_TIMEOUT_MS_CONFIG; |
7 | | -import static org.apache.kafka.clients.CommonClientConfigs.SECURITY_PROTOCOL_CONFIG; |
8 | 6 | import static org.apache.kafka.clients.CommonClientConfigs.CLIENT_ID_CONFIG; |
9 | | -import static org.apache.kafka.common.config.SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG; |
10 | | -import static org.apache.kafka.common.config.SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG; |
11 | | -import static org.apache.kafka.common.config.SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG; |
12 | | -import static org.apache.kafka.common.config.SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG; |
13 | 7 |
|
14 | 8 | public class KafkaCommonProps { |
15 | 9 | static final int KAFKA_CLIENT_REQUEST_TIMEOUT_MS_CONFIG = 5000; |
16 | 10 |
|
17 | 11 | public static Properties get(String clientId) { |
18 | | - Properties props = new Properties(); |
19 | | - props.put(BOOTSTRAP_SERVERS_CONFIG, System.getenv("KAFKA_BOOTSTRAP_SERVERS")); |
| 12 | + Properties props = ConfigUtil.getKafkaPropertiesFromEnv(); |
20 | 13 | props.put(CLIENT_ID_CONFIG, clientId); |
21 | | - props.put(REQUEST_TIMEOUT_MS_CONFIG, String.valueOf(KAFKA_CLIENT_REQUEST_TIMEOUT_MS_CONFIG)); |
22 | | - |
23 | | - String securityProtocol = System.getenv("KAFKA_SECURITY_PROTOCOL"); |
24 | | - |
25 | | - if (securityProtocol != null && securityProtocol.equals("SSL")) { |
26 | | - props.put(SECURITY_PROTOCOL_CONFIG, securityProtocol); |
27 | | - props.put(SSL_TRUSTSTORE_LOCATION_CONFIG, System.getenv("KAFKA_SSL_TRUSTSTORE_LOCATION")); |
28 | | - props.put(SSL_TRUSTSTORE_TYPE_CONFIG, System.getenv("KAFKA_SSL_TRUSTSTORE_TYPE")); |
29 | | - props.put(SSL_KEYSTORE_LOCATION_CONFIG, System.getenv("KAFKA_SSL_KEYSTORE_LOCATION")); |
30 | | - props.put(SSL_KEYSTORE_PASSWORD_CONFIG, System.getenv("KAFKA_SSL_KEYSTORE_PASSWORD")); |
31 | | - } |
32 | | - |
33 | | - props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); |
| 14 | + props.putIfAbsent(REQUEST_TIMEOUT_MS_CONFIG, String.valueOf(KAFKA_CLIENT_REQUEST_TIMEOUT_MS_CONFIG)); |
| 15 | + props.putIfAbsent("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); |
34 | 16 |
|
35 | 17 | return props; |
36 | 18 | } |
|
0 commit comments