mirror of
https://github.com/wahyd4/spring-cloud-stream-samples.git
synced 2026-08-09 05:16:18 +10:00
Updates to uppercase transformer
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -9,12 +9,28 @@
|
||||
<description>Spring Cloud Stream Uppercase Transformer</description>
|
||||
|
||||
<parent>
|
||||
<groupId>io.spring.cloud.stream.sample</groupId>
|
||||
<artifactId>spring-cloud-stream-samples-parent</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.0.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<spring-cloud.version>Hoxton.BUILD-SNAPSHOT</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -82,4 +98,56 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/libs-snapshot-local</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/libs-snapshot-local</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/libs-release-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 https://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<id>uppercase-transformer-kafka</id>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<includes>
|
||||
<include>io.spring.cloud.stream.sample:uppercase-transformer-0.0.1-SNAPSHOT-kafka</include>
|
||||
</includes>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<outputFileNameMapping>uppercase-transformer-kafka.jar</outputFileNameMapping>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 https://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<id>uppercase-transformer-rabbit</id>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<includes>
|
||||
<include>io.spring.cloud.stream.sample:uppercase-transformer</include>
|
||||
</includes>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
<outputFileNameMapping>uppercase-transformer-rabbit.jar</outputFileNameMapping>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
+21
-37
@@ -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<String, String> 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<String> sendTestData() {
|
||||
return () ->
|
||||
new GenericMessage<>(this.semaphore.getAndSet(!this.semaphore.get()) ? "foo" : "bar");
|
||||
public Supplier<String> 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<String> receive() {
|
||||
return payload -> logger.info("Data received: " + payload);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Sink {
|
||||
@Input("test-sink")
|
||||
SubscribableChannel sampleSink();
|
||||
}
|
||||
|
||||
public interface Source {
|
||||
@Output("test-source")
|
||||
MessageChannel sampleSource();
|
||||
}
|
||||
}
|
||||
|
||||
-29
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user