1 package de.juplo.kafka;
3 import org.apache.kafka.clients.consumer.KafkaConsumer;
4 import org.apache.kafka.common.serialization.LongDeserializer;
5 import org.apache.kafka.common.serialization.StringDeserializer;
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;
11 import java.util.concurrent.Executors;
15 @EnableConfigurationProperties(ApplicationProperties.class)
16 public class ApplicationConfiguration
19 public EndlessConsumer endlessConsumer(
20 KafkaConsumer<String, String> kafkaConsumer,
21 ApplicationProperties properties)
23 EndlessConsumer consumer =
25 Executors.newFixedThreadPool(1),
26 properties.getClientId(),
27 properties.getTopic(),
35 @Bean(destroyMethod = "close")
36 public KafkaConsumer<String, String> kafkaConsumer(ApplicationProperties properties)
38 Properties props = new Properties();
40 props.put("bootstrap.servers", properties.getBootstrapServer());
41 props.put("group.id", properties.getGroupId());
42 props.put("client.id", properties.getClientId());
43 props.put("auto.offset.reset", properties.getAutoOffsetReset());
44 props.put("metadata.max.age.ms", "1000");
45 props.put("key.deserializer", StringDeserializer.class.getName());
46 props.put("value.deserializer", LongDeserializer.class.getName());
48 return new KafkaConsumer<>(props);