Skip to content

Commit e8fefad

Browse files
chore(spring-kafka-test): aditionate producer,consumer, compose configs, global handler exception,logs and lombok in the project
1 parent 97f8ff8 commit e8fefad

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.io.example.controller;
2+
3+
import com.io.example.controller.dto.request.MessageRequestDtoRequest;
4+
import com.io.example.controller.dto.response.GetDtoResponse;
5+
import com.io.example.producer.KafkaProducerService;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.http.HttpStatus;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.web.bind.annotation.*;
10+
11+
@RestController
12+
@RequiredArgsConstructor
13+
@RequestMapping("/v1/example")
14+
public class ExampleController {
15+
16+
private final KafkaProducerService kafkaProducerService;
17+
18+
@PostMapping("/send")
19+
public ResponseEntity<GetDtoResponse> sendMessage(@RequestBody MessageRequestDtoRequest dto){
20+
this.kafkaProducerService.sendMessage(dto.message());
21+
return ResponseEntity.status(HttpStatus.OK).body(new GetDtoResponse("Message sent successfully!"));
22+
}
23+
24+
}

spring-kafka-example/src/main/resources/application-dev.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@ spring:
33
application:
44
name: spring-kafka-example-dev
55

6+
kafka:
7+
topics:
8+
topic-1: ${KAFKA_TOPIC_1:spring-kafka-example-topic}
9+
bootstrap-servers: localhost:9092
10+
consumer:
11+
group-id: spring-kafka-example-group
12+
auto-offset-reset: earliest
13+
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
14+
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
15+
listener:
16+
missing-topics-fatal: false
17+
618
logging:
719

820
pattern:
9-
console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n"
21+
console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n"
22+
23+
level:
24+
org.apache.kafka.common.config: OFF

spring-kafka-example/src/main/resources/application.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ spring:
33
application:
44
name: spring-kafka-example-prd
55

6+
kafka:
7+
bootstrap-servers: ${KAFKA_SERVER_PORT}
8+
consumer:
9+
group-id: myGroup
10+
auto-offset-reset: earliest
11+
612
logging:
713

814
pattern:
9-
console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n"
15+
console: "%d{yyyy-MM-dd'T'HH:mm:ss} | ${spring.application.name} | %class{30} | %level | %m%n"
16+
17+
level:
18+
org.apache.kafka.common.config: OFF

spring-kafka-example/src/test/java/com/io/example/SpringKafkaExampleApplicationTests.java renamed to spring-kafka-example/src/test/java/com/io/example/SpringKafkaExampleExampleConsumerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.boot.test.context.SpringBootTest;
55

66
@SpringBootTest
7-
class SpringKafkaExampleApplicationTests {
7+
class SpringKafkaExampleExampleConsumerTests {
88

99
@Test
1010
void contextLoads() {

0 commit comments

Comments
 (0)