From 49e0a25e8e0b346c531263d453ac880552f2a923 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 7 May 2015 10:22:10 +0100 Subject: [PATCH] Add JMS Aggregator Sample Remove useless `correlation-id` header mapping --- basic/jms/README.md | 12 +++- .../integration/samples/jms/Main.java | 18 ++++- .../spring/integration/aggregation.xml | 70 +++++++++++++++++++ .../META-INF/spring/integration/common.xml | 5 +- .../samples/jms/AggregatorDemoTest.java | 63 +++++++++++++++++ build.gradle | 2 +- 6 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 basic/jms/src/main/resources/META-INF/spring/integration/aggregation.xml create mode 100644 basic/jms/src/test/java/org/springframework/integration/samples/jms/AggregatorDemoTest.java diff --git a/basic/jms/README.md b/basic/jms/README.md index 6a382121..34e7e5e0 100644 --- a/basic/jms/README.md +++ b/basic/jms/README.md @@ -12,6 +12,7 @@ It also uses the following components: 1. Poller 2. Stdout Channel Adapter (from Stream support Module) 3. Stdin Channel Adapter (from Stream support Module) +4. Aggregator It also shows an example of using Spring profiles to modify the configuration for test cases. @@ -22,10 +23,11 @@ To run the sample, simply execute the **Main** class located in the the *org.spr $ gradlew :jms:run -You will then be prompted to run one of two demos: +You will then be prompted to run one of three demos: * **GatewayDemo** * **ChannelAdapterDemo** +* **AggregationDemo** The console output should look like: @@ -43,13 +45,17 @@ The console output should look like: 1. Channel Adapter Demo 2. Gateway Demo + 3. Aggregation Demo -When running either one of the demos you will see the following prompt: + +When running any of the demos you will see the following prompt: > Please type something and hit * **GatewayDemo** uses the *DemoBean* service, which will echo the response and upper-casing it. * **ChannelAdapterDemo** will simply echo the response +* **AggregatingDemo** uses a JMS Topic; and aggregates the responses from two inbound gateways, which +invoke a flow that upper-cases the response; the aggregation returns a list of responses. -There are also test cases that exercise both demos; utilizing Spring 3.0 profiles to route the output to a QueueChannel instead of stdout. +There are also test cases that exercise each demo; utilizing Spring 3.0 profiles to route the output to a QueueChannel instead of stdout. diff --git a/basic/jms/src/main/java/org/springframework/integration/samples/jms/Main.java b/basic/jms/src/main/java/org/springframework/integration/samples/jms/Main.java index 72afe4d3..954f50a9 100644 --- a/basic/jms/src/main/java/org/springframework/integration/samples/jms/Main.java +++ b/basic/jms/src/main/java/org/springframework/integration/samples/jms/Main.java @@ -31,6 +31,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * * @author Mark Fisher * @author Gunnar Hillert + * @author Gary Russell */ public class Main { @@ -46,6 +47,11 @@ public class Main { "/META-INF/spring/integration/outboundChannelAdapter.xml" }; + private final static String[] configFilesAggregationDemo = { + "/META-INF/spring/integration/common.xml", + "/META-INF/spring/integration/aggregation.xml" + }; + public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); @@ -64,6 +70,7 @@ public class Main { System.out.println("\n Which Demo would you like to run? :\n"); System.out.println("\t1. Channel Adapter Demo"); System.out.println("\t2. Gateway Demo"); + System.out.println("\t3. Aggregation Demo"); while (true) { final String input = scanner.nextLine(); @@ -72,11 +79,18 @@ public class Main { System.out.println(" Loading Channel Adapter Demo..."); new ClassPathXmlApplicationContext(configFilesChannelAdapterDemo, Main.class); break; - } else if("2".equals(input.trim())) { + } + else if("2".equals(input.trim())) { System.out.println(" Loading Gateway Demo..."); new ClassPathXmlApplicationContext(configFilesGatewayDemo, Main.class); break; - } else { + } + else if("3".equals(input.trim())) { + System.out.println(" Loading Aggregation Demo..."); + new ClassPathXmlApplicationContext(configFilesAggregationDemo, Main.class); + break; + } + else { System.out.println("Invalid choice\n\n"); System.out.print("Enter you choice: "); } diff --git a/basic/jms/src/main/resources/META-INF/spring/integration/aggregation.xml b/basic/jms/src/main/resources/META-INF/spring/integration/aggregation.xml new file mode 100644 index 00000000..683dab76 --- /dev/null +++ b/basic/jms/src/main/resources/META-INF/spring/integration/aggregation.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basic/jms/src/main/resources/META-INF/spring/integration/common.xml b/basic/jms/src/main/resources/META-INF/spring/integration/common.xml index 388944d6..5e8a3397 100644 --- a/basic/jms/src/main/resources/META-INF/spring/integration/common.xml +++ b/basic/jms/src/main/resources/META-INF/spring/integration/common.xml @@ -14,13 +14,16 @@ - + + + + diff --git a/basic/jms/src/test/java/org/springframework/integration/samples/jms/AggregatorDemoTest.java b/basic/jms/src/test/java/org/springframework/integration/samples/jms/AggregatorDemoTest.java new file mode 100644 index 00000000..3b3fa575 --- /dev/null +++ b/basic/jms/src/test/java/org/springframework/integration/samples/jms/AggregatorDemoTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2002-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 org.springframework.integration.samples.jms; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import org.springframework.context.support.GenericXmlApplicationContext; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; + +/** + * @author Gunnar Hillert + * @author Gary Russell + */ +public class AggregatorDemoTest { + + private final static String[] configFilesGatewayDemo = { + "/META-INF/spring/integration/common.xml", + "/META-INF/spring/integration/aggregation.xml" + }; + + @Test + public void testGatewayDemo() throws InterruptedException { + + System.setProperty("spring.profiles.active", "testCase"); + + final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesGatewayDemo); + + final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class); + + stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build()); + + final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class); + + @SuppressWarnings("unchecked") + Message> reply = (Message>) queueChannel.receive(20000); + Assert.assertNotNull(reply); + List out = reply.getPayload(); + + Assert.assertEquals("[JMS TEST, JMS TEST]", out.toString()); + + applicationContext.close(); + } + +} diff --git a/build.gradle b/build.gradle index 29e62a16..5486e722 100644 --- a/build.gradle +++ b/build.gradle @@ -193,7 +193,7 @@ subprojects { subproject -> postgresVersion = '9.1-901-1.jdbc4' subethasmtpVersion = '1.2' slf4jVersion = '1.7.6' - springIntegrationVersion = '4.1.1.RELEASE' + springIntegrationVersion = '4.1.3.RELEASE' springIntegrationDslVersion = '1.0.1.RELEASE' springVersion = '4.1.4.RELEASE' springSecurityVersion = '3.2.4.RELEASE'