1 package de.juplo.kafka;
3 import org.apache.kafka.clients.consumer.ConsumerRecord;
4 import org.apache.kafka.clients.consumer.KafkaConsumer;
5 import org.apache.kafka.common.serialization.LongDeserializer;
6 import org.apache.kafka.common.serialization.StringDeserializer;
7 import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.context.annotation.Configuration;
11 import java.util.Properties;
12 import java.util.concurrent.ExecutorService;
13 import java.util.concurrent.Executors;
17 @EnableConfigurationProperties(ApplicationProperties.class)
18 public class ApplicationConfiguration
21 public RecordHandler<String, Long> applicationRecordHandler()
30 public EndlessConsumer<String, Long> endlessConsumer(
31 KafkaConsumer<String, Long> kafkaConsumer,
32 ExecutorService executor,
33 RecordHandler recordHandler,
34 ApplicationProperties properties)
37 new EndlessConsumer<>(
39 properties.getClientId(),
40 properties.getTopic(),
46 public ExecutorService executor()
48 return Executors.newSingleThreadExecutor();
51 @Bean(destroyMethod = "close")
52 public KafkaConsumer<String, Long> kafkaConsumer(ApplicationProperties properties)
54 Properties props = new Properties();
56 props.put("bootstrap.servers", properties.getBootstrapServer());
57 props.put("group.id", properties.getGroupId());
58 props.put("client.id", properties.getClientId());
59 props.put("auto.offset.reset", properties.getAutoOffsetReset());
60 props.put("auto.commit.interval.ms", (int)properties.getCommitInterval().toMillis());
61 props.put("metadata.max.age.ms", "1000");
62 props.put("key.deserializer", StringDeserializer.class.getName());
63 props.put("value.deserializer", LongDeserializer.class.getName());
65 return new KafkaConsumer<>(props);