GH-2508: Upgrade Samples to 3.0.x
Resolves https://github.com/spring-projects/spring-kafka/issues/2508
This commit is contained in:
committed by
Artem Bilan
parent
23bfc785fd
commit
016e9b44c5
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
@@ -29,8 +29,9 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
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;
|
||||
@@ -59,8 +60,8 @@ public class Application {
|
||||
* 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));
|
||||
}
|
||||
|
||||
@@ -79,8 +80,8 @@ public class Application {
|
||||
}
|
||||
|
||||
@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..."));
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
@@ -27,12 +27,13 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
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;
|
||||
@@ -56,8 +57,8 @@ public class Application {
|
||||
* 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.kafka.core.KafkaTemplate;
|
||||
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;
|
||||
|
||||
@@ -48,9 +49,7 @@ import com.common.Foo2;
|
||||
@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);
|
||||
@@ -69,6 +68,23 @@ public class Application {
|
||||
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;
|
||||
|
||||
@@ -83,17 +99,7 @@ public class Application {
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
<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>
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-kafka.version>3.0.0-SNAPSHOT</spring-kafka.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
Reference in New Issue
Block a user