X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2FApplicationConfiguration.java;h=59652c086d6df66ae8adfa7b06199cda46b4ca27;hb=e09650509adafd0b28f141ea1302fa27ba69b73a;hp=0642aa444665ef51d296d3c4a6bee1be1644302e;hpb=0dadf92f6a0724e95385c4e054aff1f800ef7375;p=demos%2Fkafka%2Ftraining diff --git a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java index 0642aa4..59652c0 100644 --- a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java +++ b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java @@ -1,46 +1,29 @@ package de.juplo.kafka; -import org.apache.kafka.clients.producer.KafkaProducer; -import org.apache.kafka.common.serialization.StringSerializer; +import org.springframework.boot.autoconfigure.kafka.KafkaProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - -import java.util.Properties; +import org.springframework.kafka.annotation.EnableKafka; +import org.springframework.kafka.core.KafkaTemplate; @Configuration -@EnableConfigurationProperties(ApplicationProperties.class) +@EnableConfigurationProperties({ KafkaProperties.class, ApplicationProperties.class }) +@EnableKafka public class ApplicationConfiguration { @Bean - public RestProducer restProducer( - ApplicationProperties properties, - KafkaProducer kafkaProducer) + public RestGateway restGateway( + ApplicationProperties applicationProperties, + KafkaProperties kafkaProperties, + KafkaTemplate kafkaTemplate) { return - new RestProducer( - properties.getClientId(), - properties.getTopic(), - properties.getPartition(), - kafkaProducer); - } - - @Bean(destroyMethod = "close") - public KafkaProducer kafkaProducer(ApplicationProperties properties) - { - Properties props = new Properties(); - props.put("bootstrap.servers", properties.getBootstrapServer()); - props.put("client.id", properties.getClientId()); - props.put("acks", properties.getAcks()); - props.put("batch.size", properties.getBatchSize()); - props.put("delivery.timeout.ms", 20000); // 20 Sekunden - props.put("request.timeout.ms", 10000); // 10 Sekunden - props.put("linger.ms", properties.getLingerMs()); - props.put("compression.type", properties.getCompressionType()); - props.put("key.serializer", StringSerializer.class.getName()); - props.put("value.serializer", StringSerializer.class.getName()); - - return new KafkaProducer<>(props); + new RestGateway( + kafkaProperties.getClientId(), + applicationProperties.getTopic(), + applicationProperties.getPartition(), + kafkaTemplate); } }