INT-1380 added oddeven sample

This commit is contained in:
Oleg Zhurakousky
2010-09-16 18:03:23 -04:00
parent 800e2d7026
commit aa2151bc9d
23 changed files with 108 additions and 142 deletions

View File

@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>

1
getting-started/oddeven/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

View File

@@ -0,0 +1,3 @@
#Thu Sep 16 17:55:53 EDT 2010
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/oddeven/src/main/resources/META-INF/spring/integration/intervalOddEvenDemo.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="529" endstart\="529" start\="509" startend\="529"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="550" endstart\="550" start\="531" startend\="550"/>\n<bounds height\="112" width\="116" x\="19" y\="149"/>\n</element>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="704" endstart\="678" start\="553" startend\="619"/>\n<bounds height\="112" width\="116" x\="19" y\="281"/>\n</element>\n<element clazz\="RouterModelElement" type\="router">\n<structure end\="787" endstart\="787" start\="707" startend\="787"/>\n<bounds height\="112" width\="116" x\="155" y\="281"/>\n</element>\n<element clazz\="ServiceActivatorModelElement" type\="service-activator">\n<structure end\="846" endstart\="846" start\="790" startend\="846"/>\n<bounds height\="112" width\="116" x\="155" y\="149"/>\n</element>\n<element clazz\="ServiceActivatorModelElement" type\="service-activator">\n<structure end\="907" endstart\="907" start\="849" startend\="907"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -2,34 +2,47 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>spring-integration-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>oddeven</artifactId>
<name>Spring Integration Odd-Even Sample</name>
<version>2.0.0</version>
<packaging>jar</packaging>
<properties>
<spring.integration.version>2.0.0.M7</spring.integration.version>
<log4j.version>1.2.15</log4j.version>
<junit.version>4.7</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repository.springframework.maven.release</id>
<name>Spring Framework Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>repository.springframework.maven.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>repository.springframework.maven.snapshot</id>
<name>Spring Framework Maven Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1 +1,20 @@
Demonstrates Inbound channel adapter and Poller configuration with Cron and Interval triggers
This example demonstrates the following aspects of the CORE EIP support available with Spring Integration:
1. Inbound Channel Adapter
2. Filter
3. Router (SpEL based)
4. Poller with Cron and Interval Trigers
Messages are simply being emitted by the Poller (interval based or cron) triggering 'next()' method of Counter class and
sent to a 'numbers' channel - Inbound Channel Adapter. From the 'numbers' channel Messages are sent
to an expression-based router (Spring Expression Language). ALl that router does is simply routing messages
to OddLogger and EvenLogger service
To execute the Interval-based sample simply run IntervalOddEvenDemoTest class and for Cron-based sample simply
run CronOddEvenDemo class, You should see the output similar to this:
INFO : org.springframework.integration.samples.oddeven.OddLogger - odd: 1 at 2010-09-16 05:55:46
INFO : org.springframework.integration.samples.oddeven.EvenLogger - even: 2 at 2010-09-16 05:55:49
INFO : org.springframework.integration.samples.oddeven.OddLogger - odd: 3 at 2010-09-16 05:55:52
INFO : org.springframework.integration.samples.oddeven.EvenLogger - even: 4 at 2010-09-16 05:55:55

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.samples.oddeven;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
@@ -30,10 +31,11 @@ import org.springframework.integration.annotation.ServiceActivator;
*/
@MessageEndpoint
public class EvenLogger {
private static Logger logger = Logger.getLogger(EvenLogger.class);
@ServiceActivator
public void log(int i) {
System.out.println("even: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
logger.info("even: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.samples.oddeven;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
@@ -30,10 +31,11 @@ import org.springframework.integration.annotation.ServiceActivator;
*/
@MessageEndpoint
public class OddLogger {
private static Logger logger = Logger.getLogger(OddLogger.class);
@ServiceActivator
public void log(int i) {
System.out.println("odd: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
logger.info("odd: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
}
}

View File

@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<annotation-config/>
<channel id="even"/>
<channel id="odd"/>
<inbound-channel-adapter id="numbers" ref="counter" method="next">
<poller max-messages-per-poll="1" fixed-delay="3000"/>
</inbound-channel-adapter>
<filter input-channel="numbers" output-channel="positives"
expression="payload > 0"
discard-channel="nullChannel"/>
<router input-channel="positives" expression="payload % 2 == 0 ? 'even' : 'odd'"/>
<service-activator input-channel="odd" ref="oddLogger"/>
<service-activator input-channel="even" ref="evenLogger"/>
<beans:bean id="counter" class="org.springframework.integration.samples.oddeven.Counter"/>
<beans:bean id="oddLogger" class="org.springframework.integration.samples.oddeven.OddLogger"/>
<beans:bean id="evenLogger" class="org.springframework.integration.samples.oddeven.EvenLogger"/>
</beans:beans>

View File

@@ -16,11 +16,7 @@
<poller max-messages-per-poll="1" fixed-delay="3000"/>
</inbound-channel-adapter>
<filter input-channel="numbers" output-channel="positives"
expression="payload > 0"
discard-channel="nullChannel"/>
<router input-channel="positives" expression="payload % 2 == 0 ? 'even' : 'odd'"/>
<router input-channel="numbers" expression="payload % 2 == 0 ? 'even' : 'odd'"/>
<service-activator input-channel="odd" ref="oddLogger"/>

View File

@@ -35,7 +35,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class CronOddEvenDemo {
public static void main(String[] args) {
new ClassPathXmlApplicationContext("cronOddEvenDemo.xml", CronOddEvenDemo.class);
new ClassPathXmlApplicationContext("/META-INF/spring/integration/cronOddEvenDemo.xml", CronOddEvenDemo.class);
}
}

View File

@@ -31,10 +31,10 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*
* @author Mark Fisher
*/
public class IntervalOddEvenDemo {
public class IntervalOddEvenDemoTest {
public static void main(String[] args) {
new ClassPathXmlApplicationContext("intervalOddEvenDemo.xml", IntervalOddEvenDemo.class);
new ClassPathXmlApplicationContext("/META-INF/spring/integration/intervalOddEvenDemo.xml", IntervalOddEvenDemoTest.class);
}
}

View File

@@ -15,8 +15,8 @@
<level value="warn" />
</logger>
<logger name="org.springframework.integration">
<level value="warn" />
<logger name="org.springframework.integration.samples">
<level value="debug" />
</logger>
<logger name="org.springframework.integration.channel.NullChannel">

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.springframework.integration">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.channel.NullChannel">
<level value="debug" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<annotation-config/>
<channel id="even"/>
<channel id="odd"/>
<inbound-channel-adapter id="numbers" ref="counter" method="next">
<poller max-messages-per-poll="1" cron="1,2,3,5,8,13,21,34,55 * * * * ?"/>
</inbound-channel-adapter>
<filter input-channel="numbers" output-channel="positives"
expression="payload > 0"
discard-channel="nullChannel"/>
<router input-channel="positives" expression="payload % 2 == 0 ? 'even' : 'odd'"/>
<service-activator input-channel="odd" ref="oddLogger"/>
<service-activator input-channel="even" ref="evenLogger"/>
<beans:bean id="counter" class="org.springframework.integration.samples.oddeven.Counter"/>
<beans:bean id="oddLogger" class="org.springframework.integration.samples.oddeven.OddLogger"/>
<beans:bean id="evenLogger" class="org.springframework.integration.samples.oddeven.EvenLogger"/>
</beans:beans>

View File

@@ -1,5 +0,0 @@
#Generated by Maven
#Sat Sep 04 08:22:31 EDT 2010
version=2.0.0.BUILD-SNAPSHOT
groupId=org.springframework.integration.samples
artifactId=oddeven