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.SpringApplication;
7 import org.springframework.boot.autoconfigure.SpringBootApplication;
8 import org.springframework.boot.context.properties.EnableConfigurationProperties;
9 import org.springframework.context.annotation.Bean;
11 import java.util.Properties;
12 import java.util.concurrent.Executors;
15 @SpringBootApplication
16 @EnableConfigurationProperties(ApplicationProperties.class)
17 public class Application
20 public EndlessConsumer endlessConsumer(
21 KafkaConsumer<String, String> kafkaConsumer,
22 ApplicationProperties properties)
24 EndlessConsumer consumer =
26 Executors.newFixedThreadPool(1),
27 properties.getClientId(),
28 properties.getTopic(),
36 @Bean(destroyMethod = "close")
37 public KafkaConsumer<String, String> kafkaConsumer(ApplicationProperties properties)
39 Properties props = new Properties();
41 props.put("bootstrap.servers", properties.getBootstrapServer());
42 props.put("group.id", properties.getGroupId());
43 props.put("client.id", properties.getClientId());
44 props.put("auto.offset.reset", properties.getAutoOffsetReset());
45 props.put("metadata.max.age.ms", "1000");
46 props.put("key.deserializer", StringDeserializer.class.getName());
47 props.put("value.deserializer", LongDeserializer.class.getName());
49 return new KafkaConsumer<>(props);
53 public static void main(String[] args)
55 SpringApplication.run(Application.class, args);