diff --git a/basic/oddeven/README.md b/basic/oddeven/README.md index 7875e567..566029d2 100644 --- a/basic/oddeven/README.md +++ b/basic/oddeven/README.md @@ -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 diff --git a/basic/oddeven/pom.xml b/basic/oddeven/pom.xml index 382c4d7c..5fc359e7 100644 --- a/basic/oddeven/pom.xml +++ b/basic/oddeven/pom.xml @@ -1,52 +1,77 @@ - 4.0.0 - org.springframework.integration.samples - oddeven - Samples (Basic) - Odd-Even Sample - 2.1.0.BUILD-SNAPSHOT - jar - - UTF-8 - 2.1.0.RELEASE - 1.2.16 - 4.10 - - - - org.springframework.integration - spring-integration-core - ${spring.integration.version} - - - log4j - log4j - ${log4j.version} - - - - junit - junit - ${junit.version} - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.5 - 1.5 - -Xlint:all - true - false - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.springframework.integration.samples + oddeven + Samples (Basic) - Odd-Even Sample + 2.1.0.BUILD-SNAPSHOT + jar + + UTF-8 + 2.1.0.RELEASE + 1.2.16 + 4.10 + + + + + cron + + org.springframework.integration.samples.oddeven.CronOddEvenDemo + + + + interval + + org.springframework.integration.samples.oddeven.IntervalOddEvenDemoTestApp + + + + + + + org.springframework.integration + spring-integration-core + ${spring.integration.version} + + + log4j + log4j + ${log4j.version} + + + + junit + junit + ${junit.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + -Xlint:all + true + false + + + + org.codehaus.mojo + exec-maven-plugin + 1.2 + + ${java.main.class} + + + + repo.springsource.org.milestone diff --git a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/Counter.java b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/Counter.java index 736989d8..841b6def 100644 --- a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/Counter.java +++ b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/Counter.java @@ -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. *

* Every 5th number will be returned as a negative value. - * + * * @author Mark Fisher */ public class Counter { diff --git a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/CronOddEvenDemo.java b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/CronOddEvenDemo.java index e540e956..4fbbc3f0 100644 --- a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/CronOddEvenDemo.java +++ b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/CronOddEvenDemo.java @@ -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; *

* 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 { diff --git a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/EvenLogger.java b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/EvenLogger.java index ac4937b0..bae0f372 100644 --- a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/EvenLogger.java +++ b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/EvenLogger.java @@ -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())); diff --git a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/IntervalOddEvenDemoTestApp.java b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/IntervalOddEvenDemoTestApp.java index f1bd7c40..d5d49fee 100644 --- a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/IntervalOddEvenDemoTestApp.java +++ b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/IntervalOddEvenDemoTestApp.java @@ -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. *

* See the 'intervalOddEvenDemo.xml' configuration file for more detail. - * + * * @author Mark Fisher */ public class IntervalOddEvenDemoTestApp { diff --git a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/OddLogger.java b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/OddLogger.java index cd237a8d..ac422254 100644 --- a/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/OddLogger.java +++ b/basic/oddeven/src/main/java/org/springframework/integration/samples/oddeven/OddLogger.java @@ -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())); } } \ No newline at end of file diff --git a/basic/oddeven/src/main/resources/META-INF/spring/integration/intervalOddEvenDemo.xml b/basic/oddeven/src/main/resources/META-INF/spring/integration/intervalOddEvenDemo.xml index 200e4a8c..1aac0833 100644 --- a/basic/oddeven/src/main/resources/META-INF/spring/integration/intervalOddEvenDemo.xml +++ b/basic/oddeven/src/main/resources/META-INF/spring/integration/intervalOddEvenDemo.xml @@ -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">