Skip to content

Commit

Permalink
INTSAMPLES-55 - Update README.md for OddEven Sample
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ghillert committed Feb 13, 2012
1 parent d3f789b commit a60a5b2
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 79 deletions.
56 changes: 44 additions & 12 deletions basic/oddeven/README.md
Original file line number Diff line number Diff line change
@@ -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

119 changes: 72 additions & 47 deletions basic/oddeven/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,7 +24,7 @@
* Adapter acting as a Polling Consumer.
* <p/>
* Every 5th number will be returned as a negative value.
*
*
* @author Mark Fisher
*/
public class Counter {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,7 +29,7 @@
* <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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,14 +25,14 @@

/**
* 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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,7 +25,7 @@

/**
* A POJO Service Activator that logs odd numbers and the current time.
*
*
* @author Mark Fisher
* @author Marius Bogoevici
*/
Expand All @@ -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()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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/>

Expand Down

0 comments on commit a60a5b2

Please sign in to comment.