Skip to content

Commit 016e9b4

Browse files
garyrussellartembilan
authored andcommitted
GH-2508: Upgrade Samples to 3.0.x
Resolves #2508
1 parent 23bfc78 commit 016e9b4

File tree

8 files changed

+48
-41
lines changed

8 files changed

+48
-41
lines changed

samples/sample-01/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.example</groupId>
77
<artifactId>kafka-sample-01</artifactId>
8-
<version>2.6.5</version>
8+
<version>3.0.2-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>kafka-sample-01</name>
@@ -14,14 +14,14 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.4.3</version>
17+
<version>3.0.1-SNAPSHOT</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
24+
<java.version>17</java.version>
2525
</properties>
2626

2727
<dependencies>

samples/sample-01/src/main/java/com/example/Application.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2021 the original author or authors.
2+
* Copyright 2018-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,9 @@
2929
import org.springframework.core.task.TaskExecutor;
3030
import org.springframework.kafka.annotation.KafkaListener;
3131
import org.springframework.kafka.core.KafkaOperations;
32+
import org.springframework.kafka.listener.CommonErrorHandler;
3233
import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
33-
import org.springframework.kafka.listener.SeekToCurrentErrorHandler;
34+
import org.springframework.kafka.listener.DefaultErrorHandler;
3435
import org.springframework.kafka.support.converter.JsonMessageConverter;
3536
import org.springframework.kafka.support.converter.RecordMessageConverter;
3637
import org.springframework.util.backoff.FixedBackOff;
@@ -59,8 +60,8 @@ public static void main(String[] args) {
5960
* Boot will autowire this into the container factory.
6061
*/
6162
@Bean
62-
public SeekToCurrentErrorHandler errorHandler(KafkaOperations<Object, Object> template) {
63-
return new SeekToCurrentErrorHandler(
63+
public CommonErrorHandler errorHandler(KafkaOperations<Object, Object> template) {
64+
return new DefaultErrorHandler(
6465
new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 2));
6566
}
6667

@@ -79,8 +80,8 @@ public void listen(Foo2 foo) {
7980
}
8081

8182
@KafkaListener(id = "dltGroup", topics = "topic1.DLT")
82-
public void dltListen(String in) {
83-
logger.info("Received from DLT: " + in);
83+
public void dltListen(byte[] in) {
84+
logger.info("Received from DLT: " + new String(in));
8485
this.exec.execute(() -> System.out.println("Hit Enter to terminate..."));
8586
}
8687

samples/sample-02/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.example</groupId>
77
<artifactId>kafka-sample-02</artifactId>
8-
<version>2.6.5</version>
8+
<version>3.0.2-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>kafka-sample-02</name>
@@ -14,14 +14,14 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.4.3</version>
17+
<version>3.0.1-SNAPSHOT</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
24+
<java.version>17</java.version>
2525
</properties>
2626

2727
<dependencies>

samples/sample-02/src/main/java/com/example/Application.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2021 the original author or authors.
2+
* Copyright 2018-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,12 +27,13 @@
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Profile;
2929
import org.springframework.kafka.core.KafkaOperations;
30+
import org.springframework.kafka.listener.CommonErrorHandler;
3031
import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
31-
import org.springframework.kafka.listener.SeekToCurrentErrorHandler;
32-
import org.springframework.kafka.support.converter.DefaultJackson2JavaTypeMapper;
33-
import org.springframework.kafka.support.converter.Jackson2JavaTypeMapper.TypePrecedence;
32+
import org.springframework.kafka.listener.DefaultErrorHandler;
3433
import org.springframework.kafka.support.converter.JsonMessageConverter;
3534
import org.springframework.kafka.support.converter.RecordMessageConverter;
35+
import org.springframework.kafka.support.mapping.DefaultJackson2JavaTypeMapper;
36+
import org.springframework.kafka.support.mapping.Jackson2JavaTypeMapper.TypePrecedence;
3637
import org.springframework.util.backoff.FixedBackOff;
3738

3839
import com.common.Bar2;
@@ -56,8 +57,8 @@ public static void main(String[] args) {
5657
* Boot will autowire this into the container factory.
5758
*/
5859
@Bean
59-
public SeekToCurrentErrorHandler errorHandler(KafkaOperations<Object, Object> template) {
60-
return new SeekToCurrentErrorHandler(
60+
public CommonErrorHandler errorHandler(KafkaOperations<Object, Object> template) {
61+
return new DefaultErrorHandler(
6162
new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 2));
6263
}
6364

samples/sample-03/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.example</groupId>
77
<artifactId>kafka-sample-03</artifactId>
8-
<version>2.6.5</version>
8+
<version>3.0.2-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>kafka-sample-03</name>
@@ -14,14 +14,14 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.4.3</version>
17+
<version>3.0.1-SNAPSHOT</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>1.8</java.version>
24+
<java.version>17</java.version>
2525
</properties>
2626

2727
<dependencies>

samples/sample-03/src/main/java/com/example/Application.java

+20-14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.kafka.support.converter.BatchMessagingMessageConverter;
3636
import org.springframework.kafka.support.converter.JsonMessageConverter;
3737
import org.springframework.kafka.support.converter.RecordMessageConverter;
38+
import org.springframework.stereotype.Component;
3839

3940
import com.common.Foo2;
4041

@@ -48,9 +49,7 @@
4849
@SpringBootApplication
4950
public class Application {
5051

51-
private final Logger LOGGER = LoggerFactory.getLogger(Application.class);
52-
53-
private final static CountDownLatch LATCH = new CountDownLatch(1);
52+
final static CountDownLatch LATCH = new CountDownLatch(1);
5453

5554
public static void main(String[] args) throws InterruptedException {
5655
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
@@ -69,6 +68,23 @@ public BatchMessagingMessageConverter batchConverter() {
6968
return new BatchMessagingMessageConverter(converter());
7069
}
7170

71+
@Bean
72+
public NewTopic topic2() {
73+
return TopicBuilder.name("topic2").partitions(1).replicas(1).build();
74+
}
75+
76+
@Bean
77+
public NewTopic topic3() {
78+
return TopicBuilder.name("topic3").partitions(1).replicas(1).build();
79+
}
80+
81+
}
82+
83+
@Component
84+
class Listener {
85+
86+
private static final Logger LOGGER = LoggerFactory.getLogger(Listener.class);
87+
7288
@Autowired
7389
private KafkaTemplate<String, String> kafkaTemplate;
7490

@@ -83,17 +99,7 @@ public void listen1(List<Foo2> foos) throws IOException {
8399
@KafkaListener(id = "fooGroup3", topics = "topic3")
84100
public void listen2(List<String> in) {
85101
LOGGER.info("Received: " + in);
86-
LATCH.countDown();
87-
}
88-
89-
@Bean
90-
public NewTopic topic2() {
91-
return TopicBuilder.name("topic2").partitions(1).replicas(1).build();
92-
}
93-
94-
@Bean
95-
public NewTopic topic3() {
96-
return TopicBuilder.name("topic3").partitions(1).replicas(1).build();
102+
Application.LATCH.countDown();
97103
}
98104

99105
}

samples/sample-04/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.example</groupId>
77
<artifactId>kafka-sample-04</artifactId>
8-
<version>2.7.0</version>
8+
<version>3.0.2-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>kafka-sample-04</name>
@@ -14,14 +14,14 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.5.0-SNAPSHOT</version>
17+
<version>3.0.1-SNAPSHOT</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>11</java.version>
24+
<java.version>17</java.version>
2525
</properties>
2626

2727
<dependencies>

samples/sample-05/pom.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.0.0-SNAPSHOT</version>
8+
<version>3.0.1-SNAPSHOT</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111

1212
<groupId>com.example</groupId>
1313
<artifactId>kafka-sample-05</artifactId>
14-
<version>3.0.0-SNAPSHOT</version>
14+
<version>3.0.2-SNAPSHOT</version>
1515

1616
<name>kafka-sample-05</name>
1717
<description>Kafka Sample 5</description>
1818

1919

2020
<properties>
2121
<java.version>17</java.version>
22-
<spring-kafka.version>3.0.0-SNAPSHOT</spring-kafka.version>
2322
</properties>
2423

2524
<dependencies>

0 commit comments

Comments
 (0)