Springify: `start()`/`stop()`/`destroy()` in EndlessConsumer wiederbelebt
[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.HashMap;
12 import java.util.Map;
13 import java.util.concurrent.ExecutionException;
14
15
16 @RestController
17 @RequiredArgsConstructor
18 public class DriverController
19 {
20   private final EndlessConsumer consumer;
21
22
23   @PostMapping("start")
24   public void start()
25   {
26     consumer.start();
27   }
28
29   @PostMapping("stop")
30   public void stop()
31   {
32     consumer.stop();
33   }
34
35   @GetMapping("seen")
36   public Map<Integer, Map<String, Long>> seen()
37   {
38     return new HashMap<>();
39   }
40
41   @ExceptionHandler
42   @ResponseStatus(HttpStatus.BAD_REQUEST)
43   public ErrorResponse illegalStateException(IllegalStateException e)
44   {
45     return new ErrorResponse(e.getMessage(), HttpStatus.BAD_REQUEST.value());
46   }
47 }