1 package de.juplo.kafka;
3 import org.apache.kafka.clients.producer.KafkaProducer;
4 import org.apache.kafka.common.serialization.IntegerSerializer;
5 import org.apache.kafka.common.serialization.StringSerializer;
6 import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.context.annotation.Configuration;
10 import java.util.Properties;
14 @EnableConfigurationProperties(ApplicationProperties.class)
15 public class ApplicationConfiguration
18 public RestGateway restGateway(
19 ApplicationProperties properties,
20 KafkaProducer<String, Integer> kafkaProducer)
24 properties.getClientId(),
25 properties.getTopic(),
26 properties.getPartition(),
30 @Bean(destroyMethod = "close")
31 public KafkaProducer<String, Integer> kafkaProducer(ApplicationProperties properties)
33 Properties props = new Properties();
34 props.put("bootstrap.servers", properties.getBootstrapServer());
35 props.put("client.id", properties.getClientId());
36 props.put("acks", properties.getAcks());
37 props.put("batch.size", properties.getBatchSize());
38 props.put("delivery.timeout.ms", 20000); // 20 Sekunden
39 props.put("request.timeout.ms", 10000); // 10 Sekunden
40 props.put("linger.ms", properties.getLingerMs());
41 props.put("compression.type", properties.getCompressionType());
42 props.put("key.serializer", StringSerializer.class.getName());
43 props.put("value.serializer", IntegerSerializer.class.getName());
45 return new KafkaProducer<>(props);