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)
25 Executors.newFixedThreadPool(1),
26 properties.getClientId(),
27 properties.getTopic(),
31 @Bean(destroyMethod = "close")
32 public KafkaConsumer<String, String> kafkaConsumer(ApplicationProperties properties)
34 Properties props = new Properties();
36 props.put("bootstrap.servers", properties.getBootstrapServer());
37 props.put("group.id", properties.getGroupId());
38 props.put("client.id", properties.getClientId());
39 props.put("auto.offset.reset", properties.getAutoOffsetReset());
40 props.put("metadata.max.age.ms", "1000");
41 props.put("key.deserializer", StringDeserializer.class.getName());
42 props.put("value.deserializer", LongDeserializer.class.getName());
44 return new KafkaConsumer<>(props);