Die Key-Statistiken werden in einer MongoDB gespeichert
[demos/kafka/training] / src / main / java / de / juplo / kafka / StatisticsDocument.java
1 package de.juplo.kafka;
2
3 import lombok.ToString;
4 import org.springframework.data.annotation.Id;
5 import org.springframework.data.mongodb.core.mapping.Document;
6
7 import java.util.HashMap;
8 import java.util.Map;
9
10
11 @Document(collection = "statistics")
12 @ToString
13 public class StatisticsDocument
14 {
15   @Id
16   public String id;
17   public String topic;
18   public Integer partition;
19   public Map<String, Long> statistics;
20
21   public StatisticsDocument()
22   {
23   }
24
25   public StatisticsDocument(String topic, Integer partition, Map<String, Long> statistics)
26   {
27     this.partition = partition;
28     this.statistics = statistics;
29   }
30
31   public StatisticsDocument(PartitionStatistics statistics)
32   {
33     this.topic = statistics.getPartition().topic();
34     this.id = statistics.toString();
35     this.partition = statistics.getPartition().partition();
36     this.statistics = new HashMap<>();
37     statistics.getStatistics().forEach(counter -> this.statistics.put(counter.getKey(), counter.getResult()));
38   }
39 }