diff --git a/samples/sample-01/pom.xml b/samples/sample-01/pom.xml index 8187837f..e0ff5e14 100644 --- a/samples/sample-01/pom.xml +++ b/samples/sample-01/pom.xml @@ -5,7 +5,7 @@ com.example kafka-sample-01 - 2.5.0.RELEASE + 2.6.5 jar kafka-sample-01 @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.3.0.RELEASE + 2.4.2 diff --git a/samples/sample-01/src/main/java/com/example/Application.java b/samples/sample-01/src/main/java/com/example/Application.java index a7167809..14762ec7 100644 --- a/samples/sample-01/src/main/java/com/example/Application.java +++ b/samples/sample-01/src/main/java/com/example/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2021 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. @@ -24,10 +24,11 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Profile; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.core.KafkaOperations; import org.springframework.kafka.listener.DeadLetterPublishingRecoverer; import org.springframework.kafka.listener.SeekToCurrentErrorHandler; import org.springframework.kafka.support.converter.RecordMessageConverter; @@ -58,7 +59,7 @@ public class Application { * Boot will autowire this into the container factory. */ @Bean - public SeekToCurrentErrorHandler errorHandler(KafkaTemplate template) { + public SeekToCurrentErrorHandler errorHandler(KafkaOperations template) { return new SeekToCurrentErrorHandler( new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 2)); } @@ -94,6 +95,7 @@ public class Application { } @Bean + @Profile("default") // Don't run from test(s) public ApplicationRunner runner() { return args -> { System.out.println("Hit Enter to terminate..."); diff --git a/samples/sample-01/src/test/java/com/example/ApplicationTests.java b/samples/sample-01/src/test/java/com/example/ApplicationTests.java index a1ba01a3..f2b33029 100644 --- a/samples/sample-01/src/test/java/com/example/ApplicationTests.java +++ b/samples/sample-01/src/test/java/com/example/ApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2021 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. @@ -16,14 +16,13 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.TestPropertySource; -@RunWith(SpringRunner.class) @SpringBootTest +@TestPropertySource(properties = "spring.profiles.active=test") public class ApplicationTests { @Test diff --git a/samples/sample-02/pom.xml b/samples/sample-02/pom.xml index 036ec71b..e1a225e8 100644 --- a/samples/sample-02/pom.xml +++ b/samples/sample-02/pom.xml @@ -5,7 +5,7 @@ com.example kafka-sample-02 - 2.5.0.RELEASE + 2.6.5 jar kafka-sample-02 @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.3.0.RELEASE + 2.4.2 diff --git a/samples/sample-02/src/main/java/com/example/Application.java b/samples/sample-02/src/main/java/com/example/Application.java index dcafa291..290c442e 100644 --- a/samples/sample-02/src/main/java/com/example/Application.java +++ b/samples/sample-02/src/main/java/com/example/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2021 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. @@ -25,7 +25,8 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.context.annotation.Profile; +import org.springframework.kafka.core.KafkaOperations; import org.springframework.kafka.listener.DeadLetterPublishingRecoverer; import org.springframework.kafka.listener.SeekToCurrentErrorHandler; import org.springframework.kafka.support.converter.DefaultJackson2JavaTypeMapper; @@ -55,7 +56,7 @@ public class Application { * Boot will autowire this into the container factory. */ @Bean - public SeekToCurrentErrorHandler errorHandler(KafkaTemplate template) { + public SeekToCurrentErrorHandler errorHandler(KafkaOperations template) { return new SeekToCurrentErrorHandler( new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 2)); } @@ -85,6 +86,7 @@ public class Application { } @Bean + @Profile("default") // Don't run from test(s) public ApplicationRunner runner() { return args -> { System.out.println("Hit Enter to terminate..."); diff --git a/samples/sample-02/src/main/java/com/example/MultiMethods.java b/samples/sample-02/src/main/java/com/example/MultiMethods.java index aaf8f0b1..4ddbc07e 100644 --- a/samples/sample-02/src/main/java/com/example/MultiMethods.java +++ b/samples/sample-02/src/main/java/com/example/MultiMethods.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2021 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. @@ -16,6 +16,8 @@ package com.example; +import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.core.task.TaskExecutor; import org.springframework.kafka.annotation.KafkaHandler; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Component; @@ -32,19 +34,28 @@ import com.common.Foo2; @KafkaListener(id = "multiGroup", topics = { "foos", "bars" }) public class MultiMethods { + private final TaskExecutor exec = new SimpleAsyncTaskExecutor(); + @KafkaHandler public void foo(Foo2 foo) { System.out.println("Received: " + foo); + terminateMessage(); } @KafkaHandler public void bar(Bar2 bar) { System.out.println("Received: " + bar); + terminateMessage(); } @KafkaHandler(isDefault = true) public void unknown(Object object) { System.out.println("Received unknown: " + object); + terminateMessage(); + } + + private void terminateMessage() { + this.exec.execute(() -> System.out.println("Hit Enter to terminate...")); } } diff --git a/samples/sample-02/src/test/java/com/example/ApplicationTests.java b/samples/sample-02/src/test/java/com/example/ApplicationTests.java index a1ba01a3..f2b33029 100644 --- a/samples/sample-02/src/test/java/com/example/ApplicationTests.java +++ b/samples/sample-02/src/test/java/com/example/ApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2021 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. @@ -16,14 +16,13 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.TestPropertySource; -@RunWith(SpringRunner.class) @SpringBootTest +@TestPropertySource(properties = "spring.profiles.active=test") public class ApplicationTests { @Test diff --git a/samples/sample-03/pom.xml b/samples/sample-03/pom.xml index 7730631b..4da42ea8 100644 --- a/samples/sample-03/pom.xml +++ b/samples/sample-03/pom.xml @@ -5,7 +5,7 @@ com.example kafka-sample-03 - 2.5.0.RELEASE + 2.6.5 jar kafka-sample-03 @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.3.0.RELEASE + 2.4.2 diff --git a/samples/sample-03/src/test/java/com/example/ApplicationTests.java b/samples/sample-03/src/test/java/com/example/ApplicationTests.java index a1ba01a3..aa91c366 100644 --- a/samples/sample-03/src/test/java/com/example/ApplicationTests.java +++ b/samples/sample-03/src/test/java/com/example/ApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2019 the original author or authors. + * Copyright 2018-2021 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. @@ -16,13 +16,10 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest public class ApplicationTests {