ebf8863a79e9c5a5b4bfcf615794ff474c882638
[dmaap/kafka11aaf.git] / kafkaClient / src / main / java / org / onap / dmaap / kafka / IKafkaConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * dmaap-kafka-client
4  * ================================================================================
5  * Copyright (C) 2023 Nordix Foundation. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dmaap.kafka;
22
23 import java.util.List;
24 import org.apache.kafka.common.KafkaException;
25
26 public interface IKafkaConfig {
27
28     /**
29      * Returns the list of kafka bootstrap servers.
30      *
31      * @return List of kafka bootstrap servers.
32      */
33     List<String> getKafkaBootstrapServers();
34
35     /**
36      * Kafka security protocol to be used by the client to Auth towards the kafka cluster
37      *
38      * @return Kafka security.protocol. Default is SASL_PLAINTEXT in the current onap kafka config
39      */
40     default String getKafkaSecurityProtocolConfig() {
41         return "SASL_PLAINTEXT";
42     }
43
44     /**
45      * Kafka SASL mechanism to be used by the client to Auth towards the kafka cluster
46      *
47      * @return Kafka sasl.mechanism. Default is SCRAM-SHA-512 in the current onap kafka config
48      */
49     default String getKafkaSaslMechanism() {
50         return "SCRAM-SHA-512";
51     }
52
53     /**
54      * Kafka JAAS config to be used by the client to Auth towards the kafka cluster.
55      * If overridden, must align with sasl.jaas.config convention set out by the sasl.mechanism being used
56      * otherwise, mandatory setting of the environment variable SASL_JAAS_CONFIG is required to provide default behaviour
57      * @return Kafka sasl.jaas.config
58      */
59     default String getKafkaSaslJaasConfig() {
60         String saslJaasConfFromEnv = System.getenv("SASL_JAAS_CONFIG");
61         if(saslJaasConfFromEnv != null) {
62             return saslJaasConfFromEnv;
63         } else {
64             throw new KafkaException("sasl.jaas.config not set for Kafka Consumer");
65         }
66     }
67
68     /**
69      * The timeout in seconds to wait for a response from each poll.
70      *
71      * @return Client Timeout in seconds. Default is 10 seconds
72      */
73     default int getPollingTimeout() {
74         return 10;
75     }
76
77     /**
78      * Returns the kafka consumer group defined for this component.
79      *
80      * @return KafkaConsumer group.
81      */
82     String getConsumerGroup();
83
84     /**
85      * Returns the kafka consumer id defined for this component.
86      *
87      * @return KafkaConsumer id or null.
88      */
89     String getConsumerID();
90
91     /**
92      * Returns a list of kafka topics to consume from.
93      *
94      * @return List of kafka topics or empty.
95      */
96     List<String> getConsumerTopics();
97
98     /**
99      * Returns a list of kafka topics to produce to.
100      *
101      * @return List of kafka topics or empty.
102      */
103     List<String> getProducerTopics();
104
105 }