1 package de.juplo.kafka;
3 import lombok.extern.slf4j.Slf4j;
4 import org.apache.kafka.clients.consumer.ConsumerRecord;
6 import java.util.HashMap;
11 public class AdderRecordHandler implements RecordHandler<String, String>
13 private final Map<Integer, AdderBusinessLogic> state = new HashMap<>();
17 public void accept(ConsumerRecord<String, String> record)
19 Integer partition = record.partition();
20 String user = record.key();
21 String message = record.value();
25 state.get(partition).startSum(user);
29 Long result = state.get(partition).endSum(user);
30 log.info("New result for {}: {}", user, result);
34 state.get(partition).addToSum(user, Integer.parseInt(message));
39 protected void addPartition(Integer partition, Map<String, Long> state)
41 this.state.put(partition, new AdderBusinessLogic(state));
44 protected Map<String, Long> removePartition(Integer partition)
46 return this.state.remove(partition).getState();
50 public Map<Integer, AdderBusinessLogic> getState()