|
|
|
@ -19,10 +19,11 @@ import lombok.Getter; |
|
|
|
import lombok.Setter; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.kafka.clients.CommonClientConfigs; |
|
|
|
import org.apache.kafka.clients.admin.AdminClientConfig; |
|
|
|
import org.apache.kafka.clients.consumer.ConsumerConfig; |
|
|
|
import org.apache.kafka.clients.producer.ProducerConfig; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
@ -32,8 +33,7 @@ import java.util.Properties; |
|
|
|
* Created by ashvayka on 25.09.18. |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@ConditionalOnExpression("'${queue.type:null}'=='kafka'") |
|
|
|
@ConfigurationProperties(prefix = "queue.kafka") |
|
|
|
@ConditionalOnProperty(prefix = "queue", value = "type", havingValue = "kafka") |
|
|
|
@Component |
|
|
|
public class TbKafkaSettings { |
|
|
|
|
|
|
|
@ -60,19 +60,15 @@ public class TbKafkaSettings { |
|
|
|
private short replicationFactor; |
|
|
|
|
|
|
|
@Value("${queue.kafka.max_poll_records:8192}") |
|
|
|
@Getter |
|
|
|
private int maxPollRecords; |
|
|
|
|
|
|
|
@Value("${queue.kafka.max_poll_interval_ms:0}") |
|
|
|
@Getter |
|
|
|
@Value("${queue.kafka.max_poll_interval_ms:300000}") |
|
|
|
private int maxPollIntervalMs; |
|
|
|
|
|
|
|
@Value("${queue.kafka.max_partition_fetch_bytes:16777216}") |
|
|
|
@Getter |
|
|
|
private int maxPartitionFetchBytes; |
|
|
|
|
|
|
|
@Value("${queue.kafka.fetch_max_bytes:134217728}") |
|
|
|
@Getter |
|
|
|
private int fetchMaxBytes; |
|
|
|
|
|
|
|
@Value("${queue.kafka.use_confluent_cloud:false}") |
|
|
|
@ -93,21 +89,48 @@ public class TbKafkaSettings { |
|
|
|
@Setter |
|
|
|
private List<TbKafkaProperty> other; |
|
|
|
|
|
|
|
public Properties toProps() { |
|
|
|
Properties props = new Properties(); |
|
|
|
public Properties toAdminProps() { |
|
|
|
Properties props = toProps(); |
|
|
|
props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, servers); |
|
|
|
props.put(AdminClientConfig.RETRIES_CONFIG, retries); |
|
|
|
|
|
|
|
return props; |
|
|
|
} |
|
|
|
|
|
|
|
public Properties toConsumerProps() { |
|
|
|
Properties props = toProps(); |
|
|
|
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, servers); |
|
|
|
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords); |
|
|
|
props.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, maxPartitionFetchBytes); |
|
|
|
props.put(ConsumerConfig.FETCH_MAX_BYTES_CONFIG, fetchMaxBytes); |
|
|
|
props.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalMs); |
|
|
|
|
|
|
|
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); |
|
|
|
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); |
|
|
|
return props; |
|
|
|
} |
|
|
|
|
|
|
|
public Properties toProducerProps() { |
|
|
|
Properties props = toProps(); |
|
|
|
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers); |
|
|
|
props.put(ProducerConfig.RETRIES_CONFIG, retries); |
|
|
|
props.put(ProducerConfig.ACKS_CONFIG, acks); |
|
|
|
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize); |
|
|
|
props.put(ProducerConfig.LINGER_MS_CONFIG, lingerMs); |
|
|
|
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory); |
|
|
|
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer"); |
|
|
|
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); |
|
|
|
return props; |
|
|
|
} |
|
|
|
|
|
|
|
private Properties toProps() { |
|
|
|
Properties props = new Properties(); |
|
|
|
|
|
|
|
if (useConfluent) { |
|
|
|
props.put("ssl.endpoint.identification.algorithm", sslAlgorithm); |
|
|
|
props.put("sasl.mechanism", saslMechanism); |
|
|
|
props.put("sasl.jaas.config", saslConfig); |
|
|
|
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, securityProtocol); |
|
|
|
} else { |
|
|
|
props.put(ProducerConfig.ACKS_CONFIG, acks); |
|
|
|
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize); |
|
|
|
props.put(ProducerConfig.LINGER_MS_CONFIG, lingerMs); |
|
|
|
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory); |
|
|
|
} |
|
|
|
|
|
|
|
if (other != null) { |
|
|
|
|