Skip to content

GH-2508: Upgrade Samples to 3.0.x #2509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions samples/sample-01/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.example</groupId>
<artifactId>kafka-sample-01</artifactId>
<version>2.6.5</version>
<version>3.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>kafka-sample-01</name>
Expand All @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<version>3.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand Down
13 changes: 7 additions & 6 deletions samples/sample-01/src/main/java/com/example/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2021 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,8 +29,9 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaOperations;
import org.springframework.kafka.listener.CommonErrorHandler;
import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
import org.springframework.kafka.listener.SeekToCurrentErrorHandler;
import org.springframework.kafka.listener.DefaultErrorHandler;
import org.springframework.kafka.support.converter.JsonMessageConverter;
import org.springframework.kafka.support.converter.RecordMessageConverter;
import org.springframework.util.backoff.FixedBackOff;
Expand Down Expand Up @@ -59,8 +60,8 @@ public static void main(String[] args) {
* Boot will autowire this into the container factory.
*/
@Bean
public SeekToCurrentErrorHandler errorHandler(KafkaOperations<Object, Object> template) {
return new SeekToCurrentErrorHandler(
public CommonErrorHandler errorHandler(KafkaOperations<Object, Object> template) {
return new DefaultErrorHandler(
new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 2));
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions samples/sample-02/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.example</groupId>
<artifactId>kafka-sample-02</artifactId>
<version>2.6.5</version>
<version>3.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>kafka-sample-02</name>
Expand All @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<version>3.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand Down
13 changes: 7 additions & 6 deletions samples/sample-02/src/main/java/com/example/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2021 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,12 +27,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.kafka.core.KafkaOperations;
import org.springframework.kafka.listener.CommonErrorHandler;
import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
import org.springframework.kafka.listener.SeekToCurrentErrorHandler;
import org.springframework.kafka.support.converter.DefaultJackson2JavaTypeMapper;
import org.springframework.kafka.support.converter.Jackson2JavaTypeMapper.TypePrecedence;
import org.springframework.kafka.listener.DefaultErrorHandler;
import org.springframework.kafka.support.converter.JsonMessageConverter;
import org.springframework.kafka.support.converter.RecordMessageConverter;
import org.springframework.kafka.support.mapping.DefaultJackson2JavaTypeMapper;
import org.springframework.kafka.support.mapping.Jackson2JavaTypeMapper.TypePrecedence;
import org.springframework.util.backoff.FixedBackOff;

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

Expand Down
6 changes: 3 additions & 3 deletions samples/sample-03/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.example</groupId>
<artifactId>kafka-sample-03</artifactId>
<version>2.6.5</version>
<version>3.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>kafka-sample-03</name>
Expand All @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<version>3.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand Down
34 changes: 20 additions & 14 deletions samples/sample-03/src/main/java/com/example/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.kafka.support.converter.BatchMessagingMessageConverter;
import org.springframework.kafka.support.converter.JsonMessageConverter;
import org.springframework.kafka.support.converter.RecordMessageConverter;
import org.springframework.stereotype.Component;

import com.common.Foo2;

Expand All @@ -48,9 +49,7 @@
@SpringBootApplication
public class Application {

private final Logger LOGGER = LoggerFactory.getLogger(Application.class);

private final static CountDownLatch LATCH = new CountDownLatch(1);
final static CountDownLatch LATCH = new CountDownLatch(1);

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

@Bean
public NewTopic topic2() {
return TopicBuilder.name("topic2").partitions(1).replicas(1).build();
}

@Bean
public NewTopic topic3() {
return TopicBuilder.name("topic3").partitions(1).replicas(1).build();
}

}

@Component
class Listener {

private static final Logger LOGGER = LoggerFactory.getLogger(Listener.class);

@Autowired
private KafkaTemplate<String, String> kafkaTemplate;

Expand All @@ -83,17 +99,7 @@ public void listen1(List<Foo2> foos) throws IOException {
@KafkaListener(id = "fooGroup3", topics = "topic3")
public void listen2(List<String> in) {
LOGGER.info("Received: " + in);
LATCH.countDown();
}

@Bean
public NewTopic topic2() {
return TopicBuilder.name("topic2").partitions(1).replicas(1).build();
}

@Bean
public NewTopic topic3() {
return TopicBuilder.name("topic3").partitions(1).replicas(1).build();
Application.LATCH.countDown();
}

}
6 changes: 3 additions & 3 deletions samples/sample-04/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.example</groupId>
<artifactId>kafka-sample-04</artifactId>
<version>2.7.0</version>
<version>3.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>kafka-sample-04</name>
Expand All @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand Down
5 changes: 2 additions & 3 deletions samples/sample-05/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.example</groupId>
<artifactId>kafka-sample-05</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.0.2-SNAPSHOT</version>

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


<properties>
<java.version>17</java.version>
<spring-kafka.version>3.0.0-SNAPSHOT</spring-kafka.version>
</properties>

<dependencies>
Expand Down