INTSAMPLES-55 - Update README.md for OddEven Sample
For reference: https://jira.springsource.org/browse/INTSAMPLES-55 * Update README.md to reflect correct classes * Improve documentation * Add Maven Exec Maven Plugin for easy execution from the command line
This commit is contained in:
@@ -1,21 +1,53 @@
|
||||
Odd Even Sample
|
||||
===============
|
||||
|
||||
This example demonstrates the following aspects of the CORE EIP support available with Spring Integration:
|
||||
This project contains the following 2 sample applications:
|
||||
|
||||
1. Inbound Channel Adapter
|
||||
2. Filter
|
||||
3. Router (SpEL based)
|
||||
4. Poller with Cron and Interval Trigers
|
||||
* CronOddEvenDemo
|
||||
* IntervalOddEvenDemoTestApp
|
||||
|
||||
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 the router does is simply routing messages to *OddLogger* and *EvenLogger* service
|
||||
## CronOddEvenDemo
|
||||
|
||||
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:
|
||||
This example demonstrates the following aspects of the core Enterprise Integration Patterns (EIP) support available with Spring Integration:
|
||||
|
||||
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
|
||||
* Inbound Channel Adapter
|
||||
* Poller with Cron Trigger
|
||||
* Filter
|
||||
* Router (SpEL based)
|
||||
* Service Activator
|
||||
|
||||
Messages are simply being emitted by the **Poller** (**Cron-based**) through triggering the **next()** method of the *org.springframework.integration.samples.oddeven.Counter* class. The messages are sent via the **numbers** channel to a *Spring Expression Language* (SpEL) based **Message Filter**. The filter discards any messages that contain a payload whose value is less than the number one (1).
|
||||
|
||||
Via the **positives** channel messages are sent to the a SpEL expression-based router. All that the router does is to simply route messages to one of the following two **Service Activators**:
|
||||
|
||||
* OddLogger
|
||||
* EvenLogger
|
||||
|
||||
## IntervalOddEvenDemoTestApp
|
||||
|
||||
Demonstrates a method-invoking **Inbound Channel Adapter** acting as a **Polling Consumer** with an **Interval-based trigger**. That adapter is followed, downstream, by a Content Based **Router**. The router sends to one of two channels based on whether the payload number is odd or even. Each of those two channels has an **Event Driven Consumer** ready to log the number and the current time.
|
||||
|
||||
The following Spring Integration components are being used:
|
||||
|
||||
* Inbound Channel Adapter
|
||||
* Poller with Fixed Delay Trigger
|
||||
* Router (SpEL based)
|
||||
* Service Activator
|
||||
|
||||
## Running the Samples
|
||||
|
||||
To run the two samples, simply execute either **CronOddEvenDemo** or **IntervalOddEvenDemoTestApp** in package **org.springframework.integration.samples.oddeven**. You can also execute those two samples using the [Exec Maven Plugin](http://mojo.codehaus.org/exec-maven-plugin/):
|
||||
|
||||
$ mvn clean package exec:java -P cron
|
||||
|
||||
which will execute **CronOddEvenDemo**. In order to run **IntervalOddEvenDemoTestApp**, execute:
|
||||
|
||||
$ mvn clean package exec:java -P interval
|
||||
|
||||
For both samples you should see the output similar to this:
|
||||
|
||||
INFO : org.springframework.integration.samples.oddeven.OddLogger - odd: 1 at 2012-02-10 03:29:32
|
||||
INFO : org.springframework.integration.samples.oddeven.EvenLogger - even: 2 at 2012-02-10 03:29:35
|
||||
INFO : org.springframework.integration.samples.oddeven.OddLogger - odd: 3 at 2012-02-10 03:29:38
|
||||
INFO : org.springframework.integration.samples.oddeven.EvenLogger - even: 4 at 2012-02-10 03:29:41
|
||||
|
||||
|
||||
@@ -1,52 +1,77 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>oddeven</artifactId>
|
||||
<name>Samples (Basic) - Odd-Even Sample</name>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<junit.version>4.10</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>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
<compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>false</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>oddeven</artifactId>
|
||||
<name>Samples (Basic) - Odd-Even Sample</name>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<junit.version>4.10</junit.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>cron</id>
|
||||
<properties>
|
||||
<java.main.class>org.springframework.integration.samples.oddeven.CronOddEvenDemo</java.main.class>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>interval</id>
|
||||
<properties>
|
||||
<java.main.class>org.springframework.integration.samples.oddeven.IntervalOddEvenDemoTestApp</java.main.class>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<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>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
<compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>false</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<mainClass>${java.main.class}</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.springsource.org.milestone</id>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
* Adapter acting as a Polling Consumer.
|
||||
* <p/>
|
||||
* Every 5th number will be returned as a negative value.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class Counter {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -29,7 +29,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* <p>
|
||||
* See the 'cronOddEvenDemo.xml' configuration file for more detail. The cron
|
||||
* expression is based on the Fibonacci sequence. Feel free to modify it.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CronOddEvenDemo {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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,14 +25,14 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
|
||||
/**
|
||||
* A POJO Service Activator that logs even numbers and the current time.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@MessageEndpoint
|
||||
public class EvenLogger {
|
||||
private static Logger logger = Logger.getLogger(EvenLogger.class);
|
||||
|
||||
|
||||
@ServiceActivator
|
||||
public void log(int i) {
|
||||
logger.info("even: " + i + " at " + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -13,22 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.oddeven;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Demonstrates a method-invoking inbound Channel Adapter acting as a Polling
|
||||
* Demonstrates a method-invoking Inbound Channel Adapter acting as a Polling
|
||||
* Consumer with an interval-based trigger. That adapter is followed,
|
||||
* downstream, by a simple method-invoking Message Filter that discards
|
||||
* negative numbers to the "nullChannel". Next is a Content Based Router. The
|
||||
* router sends to one of two channels based on whether the payload number is
|
||||
* odd or even. Each of those two channels has an Event Driven Consumer ready
|
||||
* to log the number and the current time.
|
||||
* downstream, by a Content Based Router. The router sends to one of two channels,
|
||||
* based on whether the payload number is odd or even. Each of those two channels
|
||||
* has an Event Driven Consumer ready to log the number and the current time.
|
||||
* <p>
|
||||
* See the 'intervalOddEvenDemo.xml' configuration file for more detail.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class IntervalOddEvenDemoTestApp {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 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,7 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
|
||||
/**
|
||||
* A POJO Service Activator that logs odd numbers and the current time.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@@ -35,7 +35,7 @@ public class OddLogger {
|
||||
|
||||
@ServiceActivator
|
||||
public void log(int i) {
|
||||
logger.info("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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
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">
|
||||
http://www.springframework.org/schema/integration/spring-integration-2.1.xsd">
|
||||
|
||||
<annotation-config/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user