|
1 | 1 | package com.onlyfullstack.springkafkaapp.controllers;
|
2 | 2 |
|
3 | 3 | import com.onlyfullstack.springkafkaapp.models.Student;
|
4 |
| -import com.onlyfullstack.springkafkaapp.producers.SimpleProducer; |
5 | 4 | import lombok.extern.slf4j.Slf4j;
|
6 |
| -import org.springframework.beans.factory.annotation.Autowired; |
7 | 5 | import org.springframework.http.HttpStatus;
|
8 | 6 | import org.springframework.kafka.core.KafkaTemplate;
|
9 | 7 | import org.springframework.web.bind.annotation.GetMapping;
|
|
19 | 17 | @RequestMapping("/kafka")
|
20 | 18 | public class ProducerController {
|
21 | 19 |
|
22 |
| - private final KafkaTemplate<String, String> simpleProducer; |
23 |
| - private final KafkaTemplate<String, Student> studentKafkaTemplate; |
| 20 | + private final KafkaTemplate<String, String> simpleProducer; |
| 21 | + private final KafkaTemplate<String, Student> studentKafkaTemplate; |
24 | 22 |
|
25 |
| - public ProducerController(KafkaTemplate<String, String> simpleProducer, |
26 |
| - KafkaTemplate<String, Student> studentKafkaTemplate) { |
27 |
| - this.simpleProducer = simpleProducer; |
28 |
| - this.studentKafkaTemplate = studentKafkaTemplate; |
29 |
| - } |
| 23 | + public ProducerController(KafkaTemplate<String, String> simpleProducer, |
| 24 | + KafkaTemplate<String, Student> studentKafkaTemplate) { |
| 25 | + this.simpleProducer = simpleProducer; |
| 26 | + this.studentKafkaTemplate = studentKafkaTemplate; |
| 27 | + } |
30 | 28 |
|
31 |
| - @GetMapping(value = "/{message}") |
32 |
| - public String message(@PathVariable("message") String message) { |
33 |
| - simpleProducer.send("simple-string-topic", message); |
34 |
| - return "Message received: " + message; |
35 |
| - } |
| 29 | + @GetMapping(value = "/{message}") |
| 30 | + public String message(@PathVariable("message") String message) { |
| 31 | + simpleProducer.send("simple-string-topic", message); |
| 32 | + return "Message received: " + message; |
| 33 | + } |
36 | 34 |
|
37 |
| - @PostMapping |
38 |
| - @ResponseStatus(HttpStatus.CREATED) |
39 |
| - public String message(@RequestBody Student student) { |
40 |
| - log.debug("Received Student in controller : {}", student); |
41 |
| - studentKafkaTemplate.send("complex-object-student-topic", student); |
42 |
| - return "Message received: " + student; |
43 |
| - } |
| 35 | + @PostMapping |
| 36 | + @ResponseStatus(HttpStatus.CREATED) |
| 37 | + public String message(@RequestBody Student student) { |
| 38 | + log.debug("Received Student in controller : {}", student); |
| 39 | + studentKafkaTemplate.send("complex-object-student-topic", student); |
| 40 | + return "Message received: " + student; |
| 41 | + } |
44 | 42 | }
|
0 commit comments