Refaktorisierung für Tests - Start des EndlessConsumer in ApplicationRunner
[demos/kafka/training] / src / main / java / de / juplo / kafka / DriverController.java
1 package de.juplo.kafka;
2
3 import lombok.RequiredArgsConstructor;
4 import org.springframework.http.HttpStatus;
5 import org.springframework.web.bind.annotation.ExceptionHandler;
6 import org.springframework.web.bind.annotation.GetMapping;
7 import org.springframework.web.bind.annotation.PostMapping;
8 import org.springframework.web.bind.annotation.ResponseStatus;
9 import org.springframework.web.bind.annotation.RestController;
10
11 import java.util.Map;
12 import java.util.concurrent.ExecutionException;
13
14
15 @RestController
16 @RequiredArgsConstructor
17 public class DriverController
18 {
19   private final EndlessConsumer consumer;
20
21
22   @PostMapping("start")
23   public void start()
24   {
25     consumer.start();
26   }
27
28   @PostMapping("stop")
29   public void stop() throws ExecutionException, InterruptedException
30   {
31     consumer.stop();
32   }
33
34   @GetMapping("seen")
35   public Map<Integer, Map<String, Long>> seen()
36   {
37     return consumer.getSeen();
38   }
39
40   @ExceptionHandler
41   @ResponseStatus(HttpStatus.BAD_REQUEST)
42   public ErrorResponse illegalStateException(IllegalStateException e)
43   {
44     return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());
45   }
46 }