Skip to content

Commit 42a4ffb

Browse files
committed
feat: spring boot 4
1 parent a80e526 commit 42a4ffb

5 files changed

Lines changed: 49 additions & 39 deletions

File tree

event-to-file/pom.xml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.5.0</version>
8+
<version>4.0.0</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>de.xxx</groupId>
@@ -27,32 +27,48 @@
2727
<url/>
2828
</scm>
2929
<properties>
30-
<java.version>21</java.version>
30+
<java.version>24</java.version>
3131
</properties>
3232
<dependencies>
33-
<dependency>
34-
<groupId>org.springframework.boot</groupId>
35-
<artifactId>spring-boot-starter-actuator</artifactId>
36-
</dependency>
37-
<dependency>
38-
<groupId>org.springframework.boot</groupId>
39-
<artifactId>spring-boot-starter-web</artifactId>
40-
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-actuator</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-kafka</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-webmvc</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-actuator-test</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-kafka-test</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
<!--
4162
<dependency>
4263
<groupId>org.springframework.kafka</groupId>
4364
<artifactId>spring-kafka</artifactId>
4465
</dependency>
45-
46-
<dependency>
47-
<groupId>org.springframework.boot</groupId>
48-
<artifactId>spring-boot-starter-test</artifactId>
49-
<scope>test</scope>
50-
</dependency>
5166
<dependency>
5267
<groupId>org.springframework.kafka</groupId>
5368
<artifactId>spring-kafka-test</artifactId>
5469
<scope>test</scope>
5570
</dependency>
71+
-->
5672
</dependencies>
5773

5874
<build>

event-to-file/src/main/java/de/xxx/eventtofile/kafka/KafkaConsumer.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
*/
1313
package de.xxx.eventtofile.kafka;
1414

15-
import com.fasterxml.jackson.core.JsonProcessingException;
16-
import com.fasterxml.jackson.databind.ObjectMapper;
1715
import de.xxx.eventtofile.model.FlightDto;
1816
import de.xxx.eventtofile.model.FlightSourceDto;
1917
import de.xxx.eventtofile.model.KafkaEventDto;
2018
import de.xxx.eventtofile.sink.FlightSinkService;
2119
import de.xxx.eventtofile.source.FlightSourceService;
2220
import org.slf4j.Logger;
2321
import org.slf4j.LoggerFactory;
22+
import org.springframework.kafka.annotation.BackOff;
2423
import org.springframework.kafka.annotation.DltHandler;
2524
import org.springframework.kafka.annotation.KafkaListener;
2625
import org.springframework.kafka.annotation.RetryableTopic;
@@ -29,8 +28,8 @@
2928
import org.springframework.kafka.support.KafkaHeaders;
3029
import org.springframework.kafka.support.SendResult;
3130
import org.springframework.messaging.handler.annotation.Header;
32-
import org.springframework.retry.annotation.Backoff;
3331
import org.springframework.stereotype.Component;
32+
import tools.jackson.databind.json.JsonMapper;
3433

3534
import java.util.UUID;
3635
import java.util.concurrent.CompletableFuture;
@@ -41,20 +40,20 @@
4140
@Component
4241
public class KafkaConsumer {
4342
private static final Logger LOGGER = LoggerFactory.getLogger(KafkaConsumer.class);
44-
private final ObjectMapper objectMapper;
43+
private final JsonMapper objectMapper;
4544
private final KafkaTemplate<String,String> kafkaTemplate;
4645
private final FlightSourceService flightSourceService;
4746
private final FlightSinkService flightSinkService;
4847

49-
public KafkaConsumer(ObjectMapper objectMapper, KafkaTemplate<String,String> kafkaTemplate,
48+
public KafkaConsumer(JsonMapper objectMapper, KafkaTemplate<String,String> kafkaTemplate,
5049
FlightSourceService flightSourceService, FlightSinkService flightSinkService) {
5150
this.objectMapper = objectMapper;
5251
this.kafkaTemplate = kafkaTemplate;
5352
this.flightSourceService = flightSourceService;
5453
this.flightSinkService = flightSinkService;
5554
}
5655

57-
@RetryableTopic(kafkaTemplate = "kafkaRetryTemplate", attempts = "3", backoff = @Backoff(delay = 1000, multiplier = 2.0),
56+
@RetryableTopic(kafkaTemplate = "kafkaRetryTemplate", attempts = "3", backOff = @BackOff(delay = 1000, multiplier = 2.0),
5857
autoCreateTopics = "true", topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE)
5958
@KafkaListener(topics = KafkaConfig.FLIGHT_TOPIC)
6059
public void consumerForFlightTopic(String message) {
@@ -68,7 +67,7 @@ public void consumerForFlightTopic(String message) {
6867
}
6968
}
7069

71-
@RetryableTopic(kafkaTemplate = "kafkaRetryTemplate", attempts = "3", backoff = @Backoff(delay = 1000, multiplier = 2.0),
70+
@RetryableTopic(kafkaTemplate = "kafkaRetryTemplate", attempts = "3", backOff = @BackOff(delay = 1000, multiplier = 2.0),
7271
autoCreateTopics = "true", topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE)
7372
@KafkaListener(topics = KafkaConfig.FLIGHT_SOURCE_TOPIC)
7473
public void consumerForFlightSourceTopic(String message) {
@@ -92,7 +91,7 @@ private boolean sendToDefaultDlt(KafkaEventDto dto) {
9291
CompletableFuture<SendResult<String, String>> listenableFuture = this.kafkaTemplate
9392
.send(KafkaConfig.DEFAULT_DLT_TOPIC, UUID.randomUUID().toString(), this.objectMapper.writeValueAsString(dto));
9493
listenableFuture.get(3, TimeUnit.SECONDS);
95-
} catch (InterruptedException | ExecutionException | TimeoutException | JsonProcessingException e) {
94+
} catch (InterruptedException | ExecutionException | TimeoutException e) {
9695
throw new RuntimeException(e);
9796
}
9897
LOGGER.info("Message send to {}. {}", KafkaConfig.DEFAULT_DLT_TOPIC, dto.toString());

event-to-file/src/main/java/de/xxx/eventtofile/kafka/KafkaProducer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
*/
1313
package de.xxx.eventtofile.kafka;
1414

15-
import com.fasterxml.jackson.databind.ObjectMapper;
1615
import de.xxx.eventtofile.model.FlightDto;
1716
import org.apache.kafka.clients.admin.AdminClient;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
2019
import org.springframework.kafka.core.KafkaTemplate;
2120
import org.springframework.kafka.support.SendResult;
2221
import org.springframework.stereotype.Component;
22+
import tools.jackson.databind.json.JsonMapper;
2323

2424
import java.util.concurrent.CompletableFuture;
2525
import java.util.concurrent.TimeUnit;
@@ -28,10 +28,10 @@
2828
public class KafkaProducer {
2929
private static final Logger LOGGER = LoggerFactory.getLogger(KafkaProducer.class);
3030
private final KafkaTemplate<String, String> kafkaTemplate;
31-
private final ObjectMapper objectMapper;
31+
private final JsonMapper objectMapper;
3232
private final AdminClient adminClient;
3333

34-
public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate, AdminClient adminClient, ObjectMapper objectMapper) {
34+
public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate, AdminClient adminClient, JsonMapper objectMapper) {
3535
this.adminClient = adminClient;
3636
this.kafkaTemplate = kafkaTemplate;
3737
this.objectMapper = objectMapper;

event-to-file/src/main/java/de/xxx/eventtofile/sink/FlightSinkService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
*/
1313
package de.xxx.eventtofile.sink;
1414

15-
import com.fasterxml.jackson.databind.ObjectMapper;
1615
import de.xxx.eventtofile.model.FlightDto;
1716
import jakarta.annotation.PostConstruct;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
2019
import org.springframework.stereotype.Service;
2120
import org.springframework.transaction.annotation.Transactional;
21+
import tools.jackson.databind.json.JsonMapper;
2222

2323
import java.io.BufferedWriter;
2424
import java.io.File;
@@ -30,9 +30,9 @@
3030
@Service
3131
public class FlightSinkService {
3232
private static final Logger log = LoggerFactory.getLogger(FlightSinkService.class);
33-
private final ObjectMapper objectMapper;
33+
private final JsonMapper objectMapper;
3434

35-
public FlightSinkService(ObjectMapper objectMapper) {
35+
public FlightSinkService(JsonMapper objectMapper) {
3636
this.objectMapper = objectMapper;
3737
}
3838

event-to-file/src/main/java/de/xxx/eventtofile/source/FlightSourceService.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@
1212
*/
1313
package de.xxx.eventtofile.source;
1414

15-
import com.fasterxml.jackson.core.JsonProcessingException;
16-
import com.fasterxml.jackson.databind.ObjectMapper;
1715
import de.xxx.eventtofile.kafka.KafkaProducer;
1816
import de.xxx.eventtofile.model.FlightDto;
1917
import de.xxx.eventtofile.model.FlightSourceDto;
2018
import org.slf4j.Logger;
2119
import org.slf4j.LoggerFactory;
2220
import org.springframework.stereotype.Service;
2321
import org.springframework.transaction.annotation.Transactional;
22+
import tools.jackson.databind.json.JsonMapper;
2423

2524
@Transactional
2625
@Service
2726
public class FlightSourceService {
2827
private static final Logger log = LoggerFactory.getLogger(FlightSourceService.class);
2928
private final KafkaProducer kafkaProducer;
30-
private final ObjectMapper objectMapper;
29+
private final JsonMapper objectMapper;
3130

32-
public FlightSourceService(KafkaProducer kafkaProducer, ObjectMapper objectMapper) {
31+
public FlightSourceService(KafkaProducer kafkaProducer, JsonMapper objectMapper) {
3332
this.kafkaProducer = kafkaProducer;
3433
this.objectMapper = objectMapper;
3534
}
@@ -44,10 +43,6 @@ private FlightDto map(FlightSourceDto dto) {
4443
}
4544

4645
private void logDto(FlightSourceDto flightSourceDto) {
47-
try {
48-
log.info(this.objectMapper.writeValueAsString(flightSourceDto));
49-
} catch (JsonProcessingException e) {
50-
throw new RuntimeException(e);
51-
}
46+
log.info(this.objectMapper.writeValueAsString(flightSourceDto));
5247
}
5348
}

0 commit comments

Comments
 (0)