|
|
@ -33,6 +33,7 @@ import org.apache.kafka.common.serialization.StringSerializer;
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
import org.springframework.core.io.Resource;
|
|
|
|
import org.springframework.kafka.listener.AbstractMessageListenerContainer.AckMode;
|
|
|
|
import org.springframework.kafka.listener.AbstractMessageListenerContainer.AckMode;
|
|
|
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Configuration properties for Spring for Apache Kafka.
|
|
|
|
* Configuration properties for Spring for Apache Kafka.
|
|
|
@ -47,18 +48,6 @@ import org.springframework.kafka.listener.AbstractMessageListenerContainer.AckMo
|
|
|
|
@ConfigurationProperties(prefix = "spring.kafka")
|
|
|
|
@ConfigurationProperties(prefix = "spring.kafka")
|
|
|
|
public class KafkaProperties {
|
|
|
|
public class KafkaProperties {
|
|
|
|
|
|
|
|
|
|
|
|
private final Consumer consumer = new Consumer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Producer producer = new Producer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Listener listener = new Listener();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Template template = new Template();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Ssl ssl = new Ssl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apache Kafka Common Properties
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Comma-delimited list of host:port pairs to use for establishing the initial
|
|
|
|
* Comma-delimited list of host:port pairs to use for establishing the initial
|
|
|
|
* connection to the Kafka cluster.
|
|
|
|
* connection to the Kafka cluster.
|
|
|
@ -76,25 +65,15 @@ public class KafkaProperties {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Map<String, String> properties = new HashMap<String, String>();
|
|
|
|
private Map<String, String> properties = new HashMap<String, String>();
|
|
|
|
|
|
|
|
|
|
|
|
public Consumer getConsumer() {
|
|
|
|
private final Consumer consumer = new Consumer();
|
|
|
|
return this.consumer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Producer getProducer() {
|
|
|
|
private final Producer producer = new Producer();
|
|
|
|
return this.producer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Listener getListener() {
|
|
|
|
private final Listener listener = new Listener();
|
|
|
|
return this.listener;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Ssl getSsl() {
|
|
|
|
private final Ssl ssl = new Ssl();
|
|
|
|
return this.ssl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Template getTemplate() {
|
|
|
|
private final Template template = new Template();
|
|
|
|
return this.template;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<String> getBootstrapServers() {
|
|
|
|
public List<String> getBootstrapServers() {
|
|
|
|
return this.bootstrapServers;
|
|
|
|
return this.bootstrapServers;
|
|
|
@ -120,6 +99,26 @@ public class KafkaProperties {
|
|
|
|
this.properties = properties;
|
|
|
|
this.properties = properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Consumer getConsumer() {
|
|
|
|
|
|
|
|
return this.consumer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Producer getProducer() {
|
|
|
|
|
|
|
|
return this.producer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Listener getListener() {
|
|
|
|
|
|
|
|
return this.listener;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Ssl getSsl() {
|
|
|
|
|
|
|
|
return this.ssl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Template getTemplate() {
|
|
|
|
|
|
|
|
return this.template;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> buildCommonProperties() {
|
|
|
|
private Map<String, Object> buildCommonProperties() {
|
|
|
|
Map<String, Object> properties = new HashMap<String, Object>();
|
|
|
|
Map<String, Object> properties = new HashMap<String, Object>();
|
|
|
|
if (this.bootstrapServers != null) {
|
|
|
|
if (this.bootstrapServers != null) {
|
|
|
@ -148,7 +147,7 @@ public class KafkaProperties {
|
|
|
|
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,
|
|
|
|
properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,
|
|
|
|
this.ssl.getTruststorePassword());
|
|
|
|
this.ssl.getTruststorePassword());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.properties != null && this.properties.size() > 0) {
|
|
|
|
if (!CollectionUtils.isEmpty(this.properties)) {
|
|
|
|
properties.putAll(this.properties);
|
|
|
|
properties.putAll(this.properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return properties;
|
|
|
|
return properties;
|
|
|
@ -163,9 +162,9 @@ public class KafkaProperties {
|
|
|
|
* instance
|
|
|
|
* instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Map<String, Object> buildConsumerProperties() {
|
|
|
|
public Map<String, Object> buildConsumerProperties() {
|
|
|
|
Map<String, Object> props = buildCommonProperties();
|
|
|
|
Map<String, Object> properties = buildCommonProperties();
|
|
|
|
props.putAll(this.consumer.buildProperties());
|
|
|
|
properties.putAll(this.consumer.buildProperties());
|
|
|
|
return props;
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -177,9 +176,9 @@ public class KafkaProperties {
|
|
|
|
* instance
|
|
|
|
* instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Map<String, Object> buildProducerProperties() {
|
|
|
|
public Map<String, Object> buildProducerProperties() {
|
|
|
|
Map<String, Object> props = buildCommonProperties();
|
|
|
|
Map<String, Object> properties = buildCommonProperties();
|
|
|
|
props.putAll(this.producer.buildProperties());
|
|
|
|
properties.putAll(this.producer.buildProperties());
|
|
|
|
return props;
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String resourceToPath(Resource resource) {
|
|
|
|
private static String resourceToPath(Resource resource) {
|
|
|
@ -425,7 +424,8 @@ public class KafkaProperties {
|
|
|
|
this.valueDeserializer);
|
|
|
|
this.valueDeserializer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.maxPollRecords != null) {
|
|
|
|
if (this.maxPollRecords != null) {
|
|
|
|
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, this.maxPollRecords);
|
|
|
|
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG,
|
|
|
|
|
|
|
|
this.maxPollRecords);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return properties;
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|