/
AbstractKafkaAvroSerDeConfig.java
119 lines (100 loc) · 5.26 KB
/
AbstractKafkaAvroSerDeConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Copyright 2015 Confluent Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package io.confluent.kafka.serializers;
import java.util.List;
import java.util.Map;
import io.confluent.common.config.AbstractConfig;
import io.confluent.common.config.ConfigDef;
import io.confluent.common.config.ConfigDef.Importance;
import io.confluent.common.config.ConfigDef.Type;
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClientConfig;
import io.confluent.kafka.schemaregistry.client.security.basicauth.BasicAuthCredentialSource;
/**
* Base class for configs for serializers and deserializers, defining a few common configs and
* defaults.
*/
public class AbstractKafkaAvroSerDeConfig extends AbstractConfig {
public static final String SCHEMA_REGISTRY_URL_CONFIG = "schema.registry.url";
public static final String
SCHEMA_REGISTRY_URL_DOC =
"Comma-separated list of URLs for schema registry instances that can be used to register "
+ "or look up schemas.";
public static final String MAX_SCHEMAS_PER_SUBJECT_CONFIG = "max.schemas.per.subject";
public static final int MAX_SCHEMAS_PER_SUBJECT_DEFAULT = 1000;
public static final String MAX_SCHEMAS_PER_SUBJECT_DOC =
"Maximum number of schemas to create or cache locally.";
public static final String AUTO_REGISTER_SCHEMAS = "auto.register.schemas";
public static final boolean AUTO_REGISTER_SCHEMAS_DEFAULT = true;
public static final String AUTO_REGISTER_SCHEMAS_DOC =
"Specify if the Serializer should attempt to register the Schema with Schema Registry";
public static final String KEY_SUBJECT_NAME_STRATEGY = "key.subject.name.strategy";
public static final String KEY_SUBJECT_NAME_STRATEGY_DEFAULT = "topic-key";
public static final String KEY_SUBJECT_NAME_STRATEGY_DOC =
"Determines how to construct the subject name under which the key schema is registered "
+ "with the schema registry";
public static final String VALUE_SUBJECT_NAME_STRATEGY = "value.subject.name.strategy";
public static final String VALUE_SUBJECT_NAME_STRATEGY_DEFAULT = "topic-value";
public static final String VALUE_SUBJECT_NAME_STRATEGY_DOC =
"Determines how to construct the subject name under which the value schema is registered "
+ "with the schema registry";
public static final String BASIC_AUTH_CREDENTIALS_SOURCE = SchemaRegistryClientConfig
.BASIC_AUTH_CREDENTIALS_SOURCE;
public static final String BASIC_AUTH_CREDENTIALS_SOURCE_DEFAULT = "URL";
public static final String BASIC_AUTH_CREDENTIALS_SOURCE_DOC =
"Specify how to pick the credentials for Basic uth header. "
+ "The supported values are URL, USER_INFO and SASL_INHERIT";
public static final String SCHEMA_REGISTRY_USER_INFO_CONFIG =
SchemaRegistryClientConfig.SCHEMA_REGISTRY_USER_INFO_CONFIG;
public static final String SCHEMA_REGISTRY_USER_INFO_DEFAULT = "";
public static final String SCHEMA_REGISTRY_USER_INFO_DOC =
"Specify the user info for Basic Auth in the form of {username}:{password}";
public static ConfigDef baseConfigDef() {
return new ConfigDef()
.define(SCHEMA_REGISTRY_URL_CONFIG, Type.LIST,
Importance.HIGH, SCHEMA_REGISTRY_URL_DOC)
.define(MAX_SCHEMAS_PER_SUBJECT_CONFIG, Type.INT, MAX_SCHEMAS_PER_SUBJECT_DEFAULT,
Importance.LOW, MAX_SCHEMAS_PER_SUBJECT_DOC)
.define(AUTO_REGISTER_SCHEMAS, Type.BOOLEAN, AUTO_REGISTER_SCHEMAS_DEFAULT,
Importance.MEDIUM, AUTO_REGISTER_SCHEMAS_DOC)
.define(KEY_SUBJECT_NAME_STRATEGY, Type.STRING, KEY_SUBJECT_NAME_STRATEGY_DEFAULT,
Importance.MEDIUM, KEY_SUBJECT_NAME_STRATEGY_DOC)
.define(VALUE_SUBJECT_NAME_STRATEGY, Type.STRING, VALUE_SUBJECT_NAME_STRATEGY_DEFAULT,
Importance.MEDIUM, VALUE_SUBJECT_NAME_STRATEGY_DOC)
.define(BASIC_AUTH_CREDENTIALS_SOURCE, Type.STRING, BASIC_AUTH_CREDENTIALS_SOURCE_DEFAULT,
ConfigDef.ValidString.in(BasicAuthCredentialSource.NAMES),
Importance.MEDIUM, BASIC_AUTH_CREDENTIALS_SOURCE_DOC)
.define(SCHEMA_REGISTRY_USER_INFO_CONFIG, Type.PASSWORD, SCHEMA_REGISTRY_USER_INFO_DEFAULT,
Importance.MEDIUM, SCHEMA_REGISTRY_USER_INFO_DOC);
}
public AbstractKafkaAvroSerDeConfig(ConfigDef config, Map<?, ?> props) {
super(config, props);
}
public int getMaxSchemasPerSubject() {
return this.getInt(MAX_SCHEMAS_PER_SUBJECT_CONFIG);
}
public List<String> getSchemaRegistryUrls() {
return this.getList(SCHEMA_REGISTRY_URL_CONFIG);
}
public boolean autoRegisterSchema() {
return this.getBoolean(AUTO_REGISTER_SCHEMAS);
}
public String keySubjectNameStrategy() {
return this.getString(KEY_SUBJECT_NAME_STRATEGY);
}
public String valueSubjectNameStrategy() {
return this.getString(VALUE_SUBJECT_NAME_STRATEGY);
}
}