-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleController.java
More file actions
25 lines (20 loc) · 956 Bytes
/
ExampleController.java
File metadata and controls
25 lines (20 loc) · 956 Bytes
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
package com.io.example.controller;
import com.io.example.controller.dto.request.MessageRequestDtoRequest;
import com.io.example.controller.dto.response.SimpleTopicDtoResponse;
import com.io.example.producer.KafkaProducerService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/example")
public class ExampleController {
private final KafkaProducerService kafkaProducerService;
@PostMapping("/send/simple-topic")
public ResponseEntity<SimpleTopicDtoResponse> sendMessageToSimpleTopic( @Valid @RequestBody MessageRequestDtoRequest dto){
this.kafkaProducerService.sendMessage(dto);
return ResponseEntity.status(HttpStatus.OK).body(new SimpleTopicDtoResponse("Message sent successfully!"));
}
}