Die Key-Statistiken werden in einer MongoDB gespeichert
[demos/kafka/training] / src / main / java / de / juplo / kafka / Application.java
1 package de.juplo.kafka;
2
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;
10
11 import java.util.concurrent.Executors;
12
13
14 @SpringBootApplication
15 @EnableConfigurationProperties(ApplicationProperties.class)
16 public class Application
17 {
18   @Autowired
19   ApplicationProperties properties;
20
21
22   @Bean
23   public EndlessConsumer consumer(PartitionStatisticsRepository repository)
24   {
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");
29
30     EndlessConsumer consumer =
31         new EndlessConsumer(
32             Executors.newFixedThreadPool(1),
33             repository,
34             properties.getBootstrapServer(),
35             properties.getGroupId(),
36             properties.getClientId(),
37             properties.getTopic(),
38             properties.getAutoOffsetReset());
39
40     consumer.start();
41
42     return consumer;
43   }
44
45   @Bean
46   public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder()
47   {
48     return
49         new Jackson2ObjectMapperBuilder().serializers(
50             new TopicPartitionSerializer(),
51             new PartitionStatisticsSerializer());
52   }
53
54
55   public static void main(String[] args)
56   {
57     SpringApplication.run(Application.class, args);
58   }
59 }