Add vanilla-samples

The aim is that these will converge over time with the XD samples
This commit is contained in:
Dave Syer
2015-07-09 10:41:25 +01:00
parent 671b57bdc0
commit e6962c514f
16 changed files with 512 additions and 27 deletions

View File

@@ -1,10 +1,11 @@
---
spring:
bus:
group: testtock
name: logger
index: 1
# uncomment below to have this module consume from a specific partition
# in the range of 0 to N-1, where N is the upstream module's partitionCount
#consumerProperties:
# partitionIndex: 1
cloud:
channels:
group: testtock
name: logger
index: 1
# uncomment below to have this module consume from a specific partition
# in the range of 0 to N-1, where N is the upstream module's partitionCount
#consumerProperties:
# partitionIndex: 1

View File

@@ -1,5 +1,6 @@
---
spring:
bus:
group: testtock
name: ticker
cloud:
channels:
group: testtock
name: ticker

View File

@@ -1,11 +1,12 @@
---
spring:
bus:
group: testtock
name: ticker
# uncomment below to use the last digit of the seconds as a partition key
# hashcode(key) % N is then applied with N being the partitionCount value
# thus, even seconds should go to the 0 queue, odd seconds to the 1 queue
#producerProperties:
# partitionKeyExpression: payload.charAt(payload.length()-1)
# partitionCount: 2
cloud:
channels:
group: testtock
name: ticker
# uncomment below to use the last digit of the seconds as a partition key
# hashcode(key) % N is then applied with N being the partitionCount value
# thus, even seconds should go to the 0 queue, odd seconds to the 1 queue
#producerProperties:
# partitionKeyExpression: payload.charAt(payload.length()-1)
# partitionCount: 2

View File

@@ -1,11 +1,12 @@
---
spring:
bus:
group: tocktap
name: logger
index: 0
tap:
group: testtock
name: ticker
cloud:
channels:
group: tocktap
name: logger
index: 0
tap:
group: testtock
name: ticker
index: 0

35
vanilla-samples/pom.xml Normal file
View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-streams-samples</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<url>http://projects.spring.io/spring-xd/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-streams-parent</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</parent>
<modules>
<module>source</module>
<module>sink</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<!--skip deploy (this is just a test module) -->
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-streams-sample-sink</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-streams-sample-sink</name>
<description>Demo project for Spring XD module</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-xd-samples</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.SinkApplication</start-class>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-streams</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.xd</groupId>
<artifactId>spring-xd-messagebus-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-lattice-connector</artifactId>
<version>1.0.2.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,50 @@
/*
* 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
*
* http://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 config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.streams.EnableChannelBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.MessageChannel;
/**
* @author Dave Syer
*
*/
@Configuration
@EnableChannelBinding
@MessageEndpoint
public class ModuleDefinition {
private static Logger logger = LoggerFactory.getLogger(ModuleDefinition.class);
@Bean
public MessageChannel input() {
return new DirectChannel();
}
@ServiceActivator(inputChannel="input")
public void loggerSink(Object payload) {
logger.info("Received: " + payload);
}
}

View File

@@ -0,0 +1,17 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import config.ModuleDefinition;
@SpringBootApplication
@ComponentScan(basePackageClasses=ModuleDefinition.class)
public class SinkApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(SinkApplication.class, args);
}
}

View File

@@ -0,0 +1,11 @@
server:
port: 8081
spring:
cloud:
channels:
outputChannelName: testtock
# uncomment below to have this module consume from a specific partition
# in the range of 0 to N-1, where N is the upstream module's partitionCount
#consumerProperties:
# partitionIndex: 1

View File

@@ -0,0 +1,20 @@
package demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SinkApplication.class)
@WebAppConfiguration
@DirtiesContext
public class ModuleApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-streams-sample-source</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-streams-sample-source</name>
<description>Demo project for Spring XD module</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-xd-samples</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.SourceApplication</start-class>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-streams</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.xd</groupId>
<artifactId>spring-xd-messagebus-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-lattice-connector</artifactId>
<version>1.0.2.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,57 @@
/*
* 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
*
* http://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 config;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.streams.EnableChannelBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.InboundChannelAdapter;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageSource;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
/**
* @author Dave Syer
*
*/
@Configuration
@EnableChannelBinding
@EnableConfigurationProperties(TimeSourceOptionsMetadata.class)
public class ModuleDefinition {
@Autowired
private TimeSourceOptionsMetadata options;
@Bean
public MessageChannel output() {
return new DirectChannel();
}
@Bean
@InboundChannelAdapter(value = "output", autoStartup = "false", poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1"))
public MessageSource<String> timerMessageSource() {
return () -> new GenericMessage<>(new SimpleDateFormat(this.options.getFormat()).format(new Date()));
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright 2013-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
*
* http://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 config;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import org.springframework.xd.module.options.mixins.MaxMessagesDefaultOneMixin;
import org.springframework.xd.module.options.mixins.PeriodicTriggerMixin;
import org.springframework.xd.module.options.spi.Mixin;
import org.springframework.xd.module.options.validation.DateFormat;
/**
* Describes options to the {@code time} source module.
*
* @author Eric Bottard
* @author Gary Russell
*/
@Mixin({ PeriodicTriggerMixin.class, MaxMessagesDefaultOneMixin.class })
public class TimeSourceOptionsMetadata {
/**
* how to render the current time, using SimpleDateFormat
*/
private String format = "yyyy-MM-dd HH:mm:ss";
/**
* time delay between messages, expressed in TimeUnits (seconds by default)
*/
private int fixedDelay = 1;
/**
* an initial delay when using a fixed delay trigger, expressed in TimeUnits (seconds by default)
*/
private int initialDelay = 0;
/**
* the time unit for the fixed and initial delays
*/
private String timeUnit = "SECONDS";
/**
* the maximum messages per poll; -1 for unlimited
*/
long maxMessages = 1;
public long getMaxMessages() {
return this.maxMessages;
}
public void setMaxMessages(long maxMessages) {
this.maxMessages = maxMessages;
}
@Min(0)
public int getInitialDelay() {
return this.initialDelay;
}
public void setInitialDelay(int initialDelay) {
this.initialDelay = initialDelay;
}
@Pattern(regexp = "(?i)(NANOSECONDS|MICROSECONDS|MILLISECONDS|SECONDS|MINUTES|HOURS|DAYS)",
message = "timeUnit must be one of NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS (case-insensitive)")
public String getTimeUnit() {
return this.timeUnit;
}
public void setTimeUnit(String timeUnit) {
this.timeUnit = timeUnit.toUpperCase();
}
@DateFormat
public String getFormat() {
return this.format;
}
public void setFormat(String format) {
this.format = format;
}
public int getFixedDelay() {
return this.fixedDelay;
}
public void setFixedDelay(int fixedDelay) {
this.fixedDelay = fixedDelay;
}
}

View File

@@ -0,0 +1,17 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import config.ModuleDefinition;
@SpringBootApplication
@ComponentScan(basePackageClasses=ModuleDefinition.class)
public class SourceApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(SourceApplication.class, args);
}
}

View File

@@ -0,0 +1,11 @@
fixedDelay: 5000
spring:
cloud:
channels:
inpoutChannelName: testtock
# uncomment below to use the last digit of the seconds as a partition key
# hashcode(key) % N is then applied with N being the partitionCount value
# thus, even seconds should go to the 0 queue, odd seconds to the 1 queue
#producerProperties:
# partitionKeyExpression: payload.charAt(payload.length()-1)
# partitionCount: 2

View File

@@ -0,0 +1,20 @@
package demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SourceApplication.class)
@WebAppConfiguration
@DirtiesContext
public class ModuleApplicationTests {
@Test
public void contextLoads() {
}
}