Skip to content

Commit 7577752

Browse files
committed
Formatting the files
1 parent 7808688 commit 7577752

File tree

6 files changed

+41
-47
lines changed

6 files changed

+41
-47
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<version>2.1.6.RELEASE</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
11-
<groupId>io.stockgeeks.springkafka</groupId>
12-
<artifactId>spring-kafka-app</artifactId>
11+
<groupId>com.onlyfullstack.springkafkaapp</groupId>
12+
<artifactId>spring-kafka-docker-tutorial</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
1414
<description>Demo project for Spring Boot</description>
1515

src/main/java/com/onlyfullstack/springkafkaapp/SpringKafkaAppApplication.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
@SpringBootApplication
1111
public class SpringKafkaAppApplication {
1212

13-
public static void main(String[] args) {
14-
SpringApplication.run(SpringKafkaAppApplication.class, args);
15-
}
13+
public static void main(String[] args) {
14+
SpringApplication.run(SpringKafkaAppApplication.class, args);
15+
}
1616

1717
}

src/main/java/com/onlyfullstack/springkafkaapp/config/KafkaConfig.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import org.springframework.beans.factory.annotation.Value;
99
import org.springframework.context.annotation.Bean;
1010
import org.springframework.context.annotation.Configuration;
11-
import org.springframework.kafka.annotation.EnableKafka;
1211
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
13-
import org.springframework.kafka.config.KafkaListenerContainerFactory;
1412
import org.springframework.kafka.core.ConsumerFactory;
1513
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
1614
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
@@ -75,17 +73,15 @@ public ConsumerFactory<String, String> consumerFactory() {
7573
return new DefaultKafkaConsumerFactory<>(config);
7674
}
7775

78-
7976
@Bean
80-
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
77+
public ConcurrentKafkaListenerContainerFactory<String, String> stringKafkaListenerContainerFactory() {
8178
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory();
8279
factory.setConsumerFactory(consumerFactory());
8380
return factory;
8481
}
8582

86-
8783
@Bean
88-
public ConsumerFactory<String, Student> userConsumerFactory() {
84+
public ConsumerFactory<String, Student> studentConsumerFactory() {
8985
Map<String, Object> config = new HashMap<>();
9086

9187
config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
@@ -97,9 +93,9 @@ public ConsumerFactory<String, Student> userConsumerFactory() {
9793
}
9894

9995
@Bean
100-
public ConcurrentKafkaListenerContainerFactory<String, Student> userKafkaListenerFactory() {
96+
public ConcurrentKafkaListenerContainerFactory<String, Student> studentKafkaListenerFactory() {
10197
ConcurrentKafkaListenerContainerFactory<String, Student> factory = new ConcurrentKafkaListenerContainerFactory<>();
102-
factory.setConsumerFactory(userConsumerFactory());
98+
factory.setConsumerFactory(studentConsumerFactory());
10399
return factory;
104100
}
105101
}

src/main/java/com/onlyfullstack/springkafkaapp/consumers/SimpleConsumer.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
@Slf4j
99
@Service
1010
public class SimpleConsumer {
11-
@KafkaListener(id = "simple-string-consumer", topics = "simple-string-topic", groupId = "group_id",
12-
containerFactory = "kafkaListenerContainerFactory")
13-
public void consumeMessage(String message) {
14-
log.info("Consumer got Simple String message: {}", message);
15-
}
11+
@KafkaListener(id = "simple-string-consumer", topics = "simple-string-topic", groupId = "group_id",
12+
containerFactory = "stringKafkaListenerContainerFactory")
13+
public void consumeMessage(String message) {
14+
log.info("Consumer got Simple String message: {}", message);
15+
}
1616

17-
@KafkaListener(id = "complex-object-consumer", topics = "complex-object-student-topic",
18-
containerFactory = "userKafkaListenerFactory", groupId = "group_json")
19-
public void consumeMessage(Student student) {
20-
log.info("Consumer got Student message: {}", student);
21-
}
17+
@KafkaListener(id = "complex-object-consumer", topics = "complex-object-student-topic",
18+
containerFactory = "studentKafkaListenerFactory", groupId = "group_json")
19+
public void consumeMessage(Student student) {
20+
log.info("Consumer got Student message: {}", student);
21+
}
2222
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.onlyfullstack.springkafkaapp.controllers;
22

33
import com.onlyfullstack.springkafkaapp.models.Student;
4-
import com.onlyfullstack.springkafkaapp.producers.SimpleProducer;
54
import lombok.extern.slf4j.Slf4j;
6-
import org.springframework.beans.factory.annotation.Autowired;
75
import org.springframework.http.HttpStatus;
86
import org.springframework.kafka.core.KafkaTemplate;
97
import org.springframework.web.bind.annotation.GetMapping;
@@ -19,26 +17,26 @@
1917
@RequestMapping("/kafka")
2018
public class ProducerController {
2119

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;
2422

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+
}
3028

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+
}
3634

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+
}
4442
}

src/test/java/com/onlyfullstack/springkafkaapp/SpringKafkaAppApplicationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
@SpringBootTest
1010
public class SpringKafkaAppApplicationTests {
1111

12-
@Test
13-
public void contextLoads() {
14-
}
12+
@Test
13+
public void contextLoads() {
14+
}
1515

1616
}

0 commit comments

Comments
 (0)