From 05e704f448c4e900276559a4fb2042d1120ce22b Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Tue, 29 Oct 2019 12:22:07 -0400 Subject: [PATCH] Updates to uppercase transformer --- .../uppercase-transformer/README.adoc | 2 +- .../uppercase-transformer/pom.xml | 76 ++++++++++++++++++- .../src/main/docker/assembly-kafka.xml | 16 ---- .../src/main/docker/assembly-rabbit.xml | 15 ---- .../main/java/demo/UppercaseTransformer.java | 58 +++++--------- .../demo/UppercaseTransformerApplication.java | 29 ------- .../src/main/resources/application.yml | 10 ++- .../java/demo/ModuleApplicationTests.java | 2 +- 8 files changed, 101 insertions(+), 107 deletions(-) delete mode 100644 processor-samples/uppercase-transformer/src/main/docker/assembly-kafka.xml delete mode 100644 processor-samples/uppercase-transformer/src/main/docker/assembly-rabbit.xml delete mode 100644 processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformerApplication.java diff --git a/processor-samples/uppercase-transformer/README.adoc b/processor-samples/uppercase-transformer/README.adoc index 96a8fc8..17494cb 100644 --- a/processor-samples/uppercase-transformer/README.adoc +++ b/processor-samples/uppercase-transformer/README.adoc @@ -18,7 +18,7 @@ The following instructions assume that you are running Kafka as a Docker image. * `./mvnw clean package` -* `java -jar target/uppercase-transformer-0.0.1-SNAPSHOT.jar` +* `java -jar target/uppercase-transformer-0.0.1-SNAPSHOT-kafka.jar` The main application is the uppercase transformer which is a processor. The application also provides a source and sink for testing. diff --git a/processor-samples/uppercase-transformer/pom.xml b/processor-samples/uppercase-transformer/pom.xml index c760d52..92abca6 100644 --- a/processor-samples/uppercase-transformer/pom.xml +++ b/processor-samples/uppercase-transformer/pom.xml @@ -9,12 +9,28 @@ Spring Cloud Stream Uppercase Transformer - io.spring.cloud.stream.sample - spring-cloud-stream-samples-parent - 0.0.1-SNAPSHOT - ../.. + org.springframework.boot + spring-boot-starter-parent + 2.2.0.RELEASE + + + Hoxton.BUILD-SNAPSHOT + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + org.springframework.boot @@ -82,4 +98,56 @@ + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot-local + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone-local + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot-local + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/libs-release-local + + false + + + + diff --git a/processor-samples/uppercase-transformer/src/main/docker/assembly-kafka.xml b/processor-samples/uppercase-transformer/src/main/docker/assembly-kafka.xml deleted file mode 100644 index 177b882..0000000 --- a/processor-samples/uppercase-transformer/src/main/docker/assembly-kafka.xml +++ /dev/null @@ -1,16 +0,0 @@ - - uppercase-transformer-kafka - - - - io.spring.cloud.stream.sample:uppercase-transformer-0.0.1-SNAPSHOT-kafka - - . - uppercase-transformer-kafka.jar - - - - diff --git a/processor-samples/uppercase-transformer/src/main/docker/assembly-rabbit.xml b/processor-samples/uppercase-transformer/src/main/docker/assembly-rabbit.xml deleted file mode 100644 index 3629ac8..0000000 --- a/processor-samples/uppercase-transformer/src/main/docker/assembly-rabbit.xml +++ /dev/null @@ -1,15 +0,0 @@ - - uppercase-transformer-rabbit - - - - io.spring.cloud.stream.sample:uppercase-transformer - - . - uppercase-transformer-rabbit.jar - - - diff --git a/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformer.java b/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformer.java index 9ad99cc..7e27ab5 100644 --- a/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformer.java +++ b/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformer.java @@ -16,70 +16,54 @@ package demo; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.cloud.stream.annotation.EnableBinding; -import org.springframework.cloud.stream.annotation.Input; -import org.springframework.cloud.stream.annotation.Output; -import org.springframework.cloud.stream.annotation.StreamListener; -import org.springframework.cloud.stream.messaging.Processor; -import org.springframework.context.annotation.Bean; -import org.springframework.integration.annotation.InboundChannelAdapter; -import org.springframework.integration.annotation.Poller; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.integration.core.MessageSource; -import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.SubscribableChannel; -import org.springframework.messaging.support.GenericMessage; -import java.util.concurrent.atomic.AtomicBoolean; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; /** * @author Dave Syer * @author Soby Chacko */ -@EnableBinding(Processor.class) +@SpringBootApplication public class UppercaseTransformer { private static Logger logger = LoggerFactory.getLogger(UppercaseTransformer.class); - @ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT) - public String transform(String payload) { - return payload.toUpperCase(); + public static void main(String[] args) { + SpringApplication.run(UppercaseTransformer.class, args); + } + + @Bean + public Function transform() { + return payload -> payload.toUpperCase(); } //Following source is used as a test producer. - @EnableBinding(Source.class) static class TestSource { private AtomicBoolean semaphore = new AtomicBoolean(true); @Bean - @InboundChannelAdapter(channel = "test-source", poller = @Poller(fixedDelay = "1000")) - public MessageSource sendTestData() { - return () -> - new GenericMessage<>(this.semaphore.getAndSet(!this.semaphore.get()) ? "foo" : "bar"); + public Supplier sendTestData() { + return () -> this.semaphore.getAndSet(!this.semaphore.get()) ? "foo" : "bar"; } } //Following sink is used as a test consumer. - @EnableBinding(Sink.class) static class TestSink { - @StreamListener("test-sink") - public void receive(String payload) { - logger.info("Data received: " + payload); + @Bean + public Consumer receive() { + return payload -> logger.info("Data received: " + payload); } } - - public interface Sink { - @Input("test-sink") - SubscribableChannel sampleSink(); - } - - public interface Source { - @Output("test-source") - MessageChannel sampleSource(); - } } diff --git a/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformerApplication.java b/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformerApplication.java deleted file mode 100644 index adb4743..0000000 --- a/processor-samples/uppercase-transformer/src/main/java/demo/UppercaseTransformerApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package demo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class UppercaseTransformerApplication { - - public static void main(String[] args) { - SpringApplication.run(UppercaseTransformerApplication.class, args); - } - -} diff --git a/processor-samples/uppercase-transformer/src/main/resources/application.yml b/processor-samples/uppercase-transformer/src/main/resources/application.yml index e8a027b..399b0ae 100644 --- a/processor-samples/uppercase-transformer/src/main/resources/application.yml +++ b/processor-samples/uppercase-transformer/src/main/resources/application.yml @@ -1,12 +1,14 @@ spring: cloud: stream: + function: + definition: transform;sendTestData;receive bindings: - output: + transform-out-0: destination: xformed - test-sink: + receive-in-0: destination: xformed - input: + transform-in-0: destination: testtock - test-source: + sendTestData-out-0: destination: testtock \ No newline at end of file diff --git a/processor-samples/uppercase-transformer/src/test/java/demo/ModuleApplicationTests.java b/processor-samples/uppercase-transformer/src/test/java/demo/ModuleApplicationTests.java index 8b76c71..03b7e5b 100644 --- a/processor-samples/uppercase-transformer/src/test/java/demo/ModuleApplicationTests.java +++ b/processor-samples/uppercase-transformer/src/test/java/demo/ModuleApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = UppercaseTransformerApplication.class) +@SpringBootTest(classes = UppercaseTransformer.class) @WebAppConfiguration @DirtiesContext public class ModuleApplicationTests {