forked from Midway91/HactoberFest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageController.java
29 lines (24 loc) · 950 Bytes
/
MessageController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.rest.kafka.controller;
import com.rest.kafka.models.Profile;
import com.rest.kafka.services.Producer;
import org.apache.coyote.Response;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1/kafka")
public class MessageController {
private final Producer producer;
public MessageController(Producer producer) {
this.producer = producer;
}
@GetMapping("/publish")
public ResponseEntity<String> publish(@RequestParam("message") String message) {
producer.sendMessage(message);
return ResponseEntity.ok("Message sent to the topic surya");
}
@PostMapping("/profile")
public ResponseEntity<String> sendProfile(@RequestBody Profile profile) {
producer.sendJSONMessage(profile);
return ResponseEntity.ok("Profile had been sent to the consumer");
}
}