1 package de.juplo.kafka;
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.boot.SpringApplication;
5 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
9 import org.springframework.util.Assert;
11 import java.util.concurrent.Executors;
14 @SpringBootApplication
15 @EnableConfigurationProperties(ApplicationProperties.class)
16 public class Application
19 ApplicationProperties properties;
23 public EndlessConsumer consumer()
25 Assert.hasText(properties.getBootstrapServer(), "consumer.bootstrap-server must be set");
26 Assert.hasText(properties.getGroupId(), "consumer.group-id must be set");
27 Assert.hasText(properties.getClientId(), "consumer.client-id must be set");
28 Assert.hasText(properties.getTopic(), "consumer.topic must be set");
30 EndlessConsumer consumer =
32 Executors.newFixedThreadPool(1),
33 properties.getBootstrapServer(),
34 properties.getGroupId(),
35 properties.getClientId(),
36 properties.getTopic(),
37 properties.getAutoOffsetReset());
45 public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder()
48 new Jackson2ObjectMapperBuilder().serializers(
49 new TopicPartitionSerializer(),
50 new PartitionStatisticsSerializer());
54 public static void main(String[] args)
56 SpringApplication.run(Application.class, args);