X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2FApplicationConfiguration.java;h=59652c086d6df66ae8adfa7b06199cda46b4ca27;hb=e09650509adafd0b28f141ea1302fa27ba69b73a;hp=33dabc93f8c1972662157b0f83a7b5827c969094;hpb=656d24e02b7e42404a508946885009b59b39e1ee;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 33dabc9..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.IntegerSerializer; -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 RestGateway restGateway( - ApplicationProperties properties, - KafkaProducer kafkaProducer) + ApplicationProperties applicationProperties, + KafkaProperties kafkaProperties, + KafkaTemplate kafkaTemplate) { return new RestGateway( - properties.getClientId(), - properties.getTopic(), - 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", IntegerSerializer.class.getName()); - - return new KafkaProducer<>(props); + kafkaProperties.getClientId(), + applicationProperties.getTopic(), + applicationProperties.getPartition(), + kafkaTemplate); } }