From a32ed6647b530db2970a15f442d343d4a1a9b377 Mon Sep 17 00:00:00 2001 From: Tom McCuch Date: Sun, 30 Oct 2011 18:52:42 -0400 Subject: [PATCH 1/7] interim commit changed copyright on Order.java --- applications/cafe/pom.xml | 4 +- .../integration/samples/cafe/Order.java | 2 +- .../samples/cafe/annotation/Barista.java | 2 +- .../amqp/cafeDemo-amqp-baristaCold-xml.xml | 61 ++++++++ .../amqp/cafeDemo-amqp-baristaHot-xml.xml | 62 ++++++++ .../integration/amqp/cafeDemo-amqp-xml.xml | 133 ++++++++++++++++++ 6 files changed, 260 insertions(+), 4 deletions(-) create mode 100644 applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml create mode 100644 applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml create mode 100644 applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml diff --git a/applications/cafe/pom.xml b/applications/cafe/pom.xml index aa0dbf58..5a80da72 100644 --- a/applications/cafe/pom.xml +++ b/applications/cafe/pom.xml @@ -7,14 +7,14 @@ 2.0.0 Spring Integration Cafe Sample - 2.0.5.RELEASE + 2.1.0.M3 1.2.16 4.7 org.springframework.integration - spring-integration-core + spring-integration-amqp ${spring.integration.version} diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java index 883d9708..6b6f68d6 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java index a3ccc9e3..3ceac0e3 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml new file mode 100644 index 00000000..ed990516 --- /dev/null +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml new file mode 100644 index 00000000..6ff636a6 --- /dev/null +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml new file mode 100644 index 00000000..d840e9b7 --- /dev/null +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 15dc7cd0593cdaf6194f7e1d5cebee20d0ae4824 Mon Sep 17 00:00:00 2001 From: Tom McCuch Date: Mon, 31 Oct 2011 13:04:28 -0400 Subject: [PATCH 2/7] domain updates + new runnable class --- .../integration/samples/cafe/Delivery.java | 14 ++++- .../integration/samples/cafe/Drink.java | 38 +++++++++++- .../integration/samples/cafe/DrinkType.java | 2 +- .../integration/samples/cafe/Order.java | 13 +++- .../integration/samples/cafe/OrderItem.java | 38 ++++++++---- .../samples/cafe/annotation/Barista.java | 10 ++-- .../integration/samples/cafe/xml/Barista.java | 12 ++-- .../samples/cafe/xml/CafeDemoAppAmqp.java | 60 +++++++++++++++++++ .../integration/amqp/cafeDemo-amqp-xml.xml | 5 +- .../cafe/src/test/resources/log4j.xml | 10 +++- 10 files changed, 172 insertions(+), 30 deletions(-) create mode 100644 applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Delivery.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Delivery.java index a59fbd43..2f0b5b49 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Delivery.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Delivery.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -20,16 +20,18 @@ import java.util.List; /** * @author Marius Bogoevici + * @author Tom McCuch */ public class Delivery { private static final String SEPARATOR = "-----------------------"; - private List deliveredDrinks; private int orderNumber; + // Default constructor required by Jackson Java JSON-processor + public Delivery() {} public Delivery(List deliveredDrinks) { assert(deliveredDrinks.size() > 0); @@ -42,10 +44,18 @@ public class Delivery { return orderNumber; } + public void setOrderNumber(int orderNumber) { + this.orderNumber = orderNumber; + } + public List getDeliveredDrinks() { return deliveredDrinks; } + public void setDeliveredDrinks(List deliveredDrinks) { + this.deliveredDrinks = deliveredDrinks; + } + @Override public String toString() { StringBuffer buffer = new StringBuffer(SEPARATOR + "\n"); diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Drink.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Drink.java index 504a8658..aa336199 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Drink.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Drink.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -18,6 +18,7 @@ package org.springframework.integration.samples.cafe; /** * @author Marius Bogoevici + * @author Tom McCuch */ public class Drink { @@ -30,10 +31,13 @@ public class Drink { private int orderNumber; - public Drink(int orderNumber, DrinkType drinkType, boolean hot, int shots) { + // Default constructor required by Jackson Java JSON-processor + public Drink() {} + + public Drink(int orderNumber, DrinkType drinkType, boolean iced, int shots) { this.orderNumber = orderNumber; this.drinkType = drinkType; - this.iced = hot; + this.iced = iced; this.shots = shots; } @@ -42,6 +46,34 @@ public class Drink { return orderNumber; } + public void setOrderNumber(int orderNumber) { + this.orderNumber = orderNumber; + } + + public boolean isIced() { + return this.iced; + } + + public void setIced(boolean iced) { + this.iced = iced; + } + + public DrinkType getDrinkType() { + return this.drinkType; + } + + public void setDrinkType(DrinkType drinkType) { + this.drinkType = drinkType; + } + + public int getShots() { + return this.shots; + } + + public void setShots(int shots) { + this.shots = shots; + } + @Override public String toString() { return (iced?"Iced":"Hot") + " " + drinkType.toString() + ", " + shots + " shots."; diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java index 7e438db4..4944ca4c 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/DrinkType.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java index 6b6f68d6..448d7186 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java @@ -22,6 +22,7 @@ import java.util.List; /** * @author Mark Fisher * @author Marius Bogoevici + * @author Tom McCuch */ public class Order { @@ -29,20 +30,30 @@ public class Order { private int number; + // Default constructor required by Jackson Java JSON-processor + public Order() {} + public Order(int number) { this.number = number; } public void addItem(DrinkType drinkType, int shots, boolean iced) { - this.orderItems.add(new OrderItem(this, drinkType, shots, iced)); + this.orderItems.add(new OrderItem(this.number, drinkType, shots, iced)); } public int getNumber() { return number; } + public void setNumber(int number) { + this.number = number; + } + public List getItems() { return this.orderItems; } + public void setItems(List orderItems) { + this.orderItems = orderItems; + } } diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java index 0215ff4c..d256bd81 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -19,6 +19,7 @@ package org.springframework.integration.samples.cafe; /** * @author Mark Fisher * @author Marius Bogoevici + * @author Tom McCuch */ public class OrderItem { @@ -28,34 +29,51 @@ public class OrderItem { private boolean iced = false; - private final Order order; + private int orderNumber; + // Default constructor required by Jackson Java JSON-processor + public OrderItem() {} - public OrderItem(Order order, DrinkType type, int shots, boolean iced) { - this.order = order; + public OrderItem(int orderNumber, DrinkType type, int shots, boolean iced) { + this.orderNumber = orderNumber; this.type = type; this.shots = shots; this.iced = iced; } - - public Order getOrder() { - return this.order; + public int getOrderNumber() { + return this.orderNumber; } + public void setOrderNumber(int orderNumber) { + this.orderNumber = orderNumber; + } + public boolean isIced() { return this.iced; } - public int getShots() { + public void setIced(boolean iced) { + this.iced = iced; + } + + public int getShots() { return shots; } - public DrinkType getDrinkType() { + public void setShots(int shots) { + this.shots = shots; + } + + public DrinkType getDrinkType() { return this.type; } - public String toString() { + public void setDrinkType(DrinkType type) { + this.type = type; + } + + public String toString() { return ((this.iced) ? "iced " : "hot ") + this.shots + " shot " + this.type; } diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java index 3ceac0e3..ece88941 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/annotation/Barista.java @@ -27,7 +27,9 @@ import org.springframework.stereotype.Component; /** * @author Mark Fisher * @author Marius Bogoevici + * @author Tom McCuch */ + @Component public class Barista { private static Logger logger = Logger.getLogger(Barista.class); @@ -54,8 +56,8 @@ public class Barista { Thread.sleep(this.hotDrinkDelay); logger.info(Thread.currentThread().getName() + " prepared hot drink #" + hotDrinkCounter.incrementAndGet() + " for order #" - + orderItem.getOrder().getNumber() + ": " + orderItem); - return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(), + + orderItem.getOrderNumber() + ": " + orderItem); + return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(), orderItem.getShots()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -69,8 +71,8 @@ public class Barista { Thread.sleep(this.coldDrinkDelay); logger.info(Thread.currentThread().getName() + " prepared cold drink #" + coldDrinkCounter.incrementAndGet() + " for order #" - + orderItem.getOrder().getNumber() + ": " + orderItem); - return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(), + + orderItem.getOrderNumber() + ": " + orderItem); + return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(), orderItem.getShots()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java index 4db79f81..c4d117f0 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/Barista.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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,9 @@ import org.springframework.integration.samples.cafe.OrderItem; /** * @author Mark Fisher * @author Marius Bogoevici + * @author Tom McCuch */ + public class Barista { private static Logger logger = Logger.getLogger(Barista.class); private long hotDrinkDelay = 5000; @@ -50,8 +52,8 @@ public class Barista { Thread.sleep(this.hotDrinkDelay); logger.info(Thread.currentThread().getName() + " prepared hot drink #" + hotDrinkCounter.incrementAndGet() + " for order #" - + orderItem.getOrder().getNumber() + ": " + orderItem); - return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(), + + orderItem.getOrderNumber() + ": " + orderItem); + return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(), orderItem.getShots()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -64,8 +66,8 @@ public class Barista { Thread.sleep(this.coldDrinkDelay); logger.info(Thread.currentThread().getName() + " prepared cold drink #" + coldDrinkCounter.incrementAndGet() + " for order #" - + orderItem.getOrder().getNumber() + ": " + orderItem); - return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(), + + orderItem.getOrderNumber() + ": " + orderItem); + return new Drink(orderItem.getOrderNumber(), orderItem.getDrinkType(), orderItem.isIced(), orderItem.getShots()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java new file mode 100644 index 00000000..23c110c6 --- /dev/null +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java @@ -0,0 +1,60 @@ +/* + * Copyright 2002-2011 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.cafe.xml; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; + +/** + * Provides the 'main' method for running the Cafe Demo application + * using AMQP. Before running, be sure to have a RabbitMQ broker + * started on localhost:5672 configured with the default + * guest | guest client credentials on the / vHost. When an order is + * placed, the Cafe will send that order to the "orders" channel. + *

+ * The relevant components are defined within the configuration files: + * ("cafeDemo-amqp-xml.xml", "cafeDemo-amqp-baristaCold-xml.xml, and + * "cafeDemo-amqp-baristaHot-xml.xml). + *

+ * If deploying in SpringSource dmServer, the relevant ApplicationContext + * configuration is in the META-INF/spring directory instead. + * + * @author Tom McCuch + */ +public class CafeDemoAppAmqp { + + public static void main(String[] args) { + AbstractApplicationContext context = + new ClassPathXmlApplicationContext( + new String[] {"/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml", + "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml", + "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml"}, + CafeDemoAppAmqp.class); + + Cafe cafe = (Cafe) context.getBean("cafe"); + for (int i = 1; i <= 100; i++) { + Order order = new Order(i); + order.addItem(DrinkType.LATTE, 2, false); + order.addItem(DrinkType.MOCHA, 3, true); + cafe.placeOrder(order); + } + context.close(); + } +} diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml index d840e9b7..b5472278 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml @@ -22,9 +22,8 @@ - - - + diff --git a/applications/cafe/src/test/resources/log4j.xml b/applications/cafe/src/test/resources/log4j.xml index 678b69b3..bbcbcf15 100644 --- a/applications/cafe/src/test/resources/log4j.xml +++ b/applications/cafe/src/test/resources/log4j.xml @@ -6,7 +6,7 @@ - + @@ -15,6 +15,14 @@ + + + + + + + + From 9c9c1da7f30f10cd6caea0e617d5797453b81079 Mon Sep 17 00:00:00 2001 From: Tom McCuch Date: Sun, 6 Nov 2011 18:21:48 -0500 Subject: [PATCH 3/7] Final Packaging --- applications/cafe/pom.xml | 11 ++ applications/cafe/readme.txt | 19 ++- .../integration/samples/cafe/Cafe.java | 2 +- .../samples/cafe/xml/CafeDemoAppAmqp.java | 19 ++- .../cafe/xml/CafeDemoAppBaristaColdAmqp.java | 59 +++++++++ .../cafe/xml/CafeDemoAppBaristaHotAmqp.java | 59 +++++++++ .../cafe/xml/CafeDemoAppOperationsAmqp.java | 65 ++++++++++ .../amqp/cafeDemo-amqp-baristaCold-xml.xml | 18 +-- .../amqp/cafeDemo-amqp-baristaHot-xml.xml | 19 +-- .../amqp/cafeDemo-amqp-config-xml.xml | 23 ++++ .../amqp/cafeDemo-amqp-operations-xml.xml | 113 ++++++++++++++++ .../integration/amqp/cafeDemo-amqp-xml.xml | 121 ++++-------------- 12 files changed, 385 insertions(+), 143 deletions(-) create mode 100644 applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java create mode 100644 applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java create mode 100644 applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java create mode 100644 applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml create mode 100644 applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml diff --git a/applications/cafe/pom.xml b/applications/cafe/pom.xml index 5a80da72..b0483d22 100644 --- a/applications/cafe/pom.xml +++ b/applications/cafe/pom.xml @@ -22,6 +22,17 @@ spring-integration-stream ${spring.integration.version} + + + org.codehaus.jackson + jackson-core-asl + 1.8.3 + + + org.codehaus.jackson + jackson-mapper-asl + 1.8.3 + log4j log4j diff --git a/applications/cafe/readme.txt b/applications/cafe/readme.txt index 69ae4e18..a0c3f488 100644 --- a/applications/cafe/readme.txt +++ b/applications/cafe/readme.txt @@ -8,7 +8,7 @@ The domain is that of a Cafe, and the basic flow is depicted in the following di |==========| -->| | orders drinks / | prepareHotDrink() | Place Order ->Cafe->|======|->OrderSplitter->|======|->DrinkRouter | | - \ coldDeinks | prepareColdDrink() | + \ coldDrinks | prepareColdDrink() | |==========| -->| | |____________________| @@ -26,11 +26,24 @@ Instructions for running the CafeDemo sample ------------------------------------------------------------------------------- 1. The example comes with two identical configurations. One is ANNOTATION-based anther is XML-based -2. To run this sample simply execute the CafeDemo* test classes +2. To run this sample simply execute the CafeDemoApp test classes in the org.springframework.integration.samples.cafe.xml or org.springframework.integration.samples.cafe.annotation package. + +3. The example also provides an alternative configuration that uses AMQP channels to distribute the components + in the CafeDemo sample. To run this alternative configuration of the sample, be sure to have a RabbitMQ broker + started on localhost:5672 configured with the default guest | guest client credentials on the / vHost, + then execute the following test classes in order: - You shoudl see the output similar to this: + 1. cafeDemoAppBaristaColdAmqp - starts the Cold Drink Barista + 2. cafeDemoAppBaristaHotAmqp- starts the Hot Drink Barista + 3. cafeDemoAppOperationsAmqp - starts the Cafe Operations (OrderSplitter, DrinkRouter, PreparedDrinkAggregator) + 4. cafeDemoAppAmqp - starts the Cafe Storefront (Places 100 orders on the orders queue) + + * Note: All AMQP exchanges, queues, and bindings needed for this sample are defined within the different xml + config files that support the above test classes. + +Upon running any of the alternatives, you should see the output similar to this: INFO : org.springframework.integration.samples.cafe.annotation.Barista - task-scheduler-1 prepared cold drink #1 for order #1: iced 3 shot MOCHA INFO : org.springframework.integration.samples.cafe.annotation.Barista - task-scheduler-1 prepared cold drink #2 for order #2: iced 3 shot MOCHA diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java index 66363ca8..fecbce4d 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java @@ -30,7 +30,7 @@ import org.springframework.integration.annotation.Gateway; */ public interface Cafe { - @Gateway(requestChannel="orders") + @Gateway(requestChannel="preOrders") void placeOrder(Order order); } diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java index 23c110c6..db802315 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java @@ -23,15 +23,15 @@ import org.springframework.integration.samples.cafe.DrinkType; import org.springframework.integration.samples.cafe.Order; /** - * Provides the 'main' method for running the Cafe Demo application - * using AMQP. Before running, be sure to have a RabbitMQ broker - * started on localhost:5672 configured with the default + * Provides the 'main' method for running the Cafe Demo store front + * application using AMQP. Before running, be sure to have a + * RabbitMQ broker started on localhost:5672 configured with the default * guest | guest client credentials on the / vHost. When an order is - * placed, the Cafe will send that order to the "orders" channel. + * placed, the Cafe store front will publish that order on the cafe-orders + * exchange to be processed. *

* The relevant components are defined within the configuration files: - * ("cafeDemo-amqp-xml.xml", "cafeDemo-amqp-baristaCold-xml.xml, and - * "cafeDemo-amqp-baristaHot-xml.xml). + * ("cafeDemo-amqp-xml.xml", "cafeDemo-amqp-config-xml.xml"). *

* If deploying in SpringSource dmServer, the relevant ApplicationContext * configuration is in the META-INF/spring directory instead. @@ -42,11 +42,7 @@ public class CafeDemoAppAmqp { public static void main(String[] args) { AbstractApplicationContext context = - new ClassPathXmlApplicationContext( - new String[] {"/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml", - "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml", - "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml"}, - CafeDemoAppAmqp.class); + new ClassPathXmlApplicationContext("/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml", CafeDemoAppAmqp.class); Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= 100; i++) { @@ -55,6 +51,7 @@ public class CafeDemoAppAmqp { order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } + context.close(); } } diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java new file mode 100644 index 00000000..bde92220 --- /dev/null +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java @@ -0,0 +1,59 @@ +/* + * Copyright 2002-2011 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.cafe.xml; + +import java.io.IOException; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; + +/** + * Provides the 'main' method for running the Cafe Demo Cold Drink + * Barista application using AMQP. Before running, be sure to have a + * RabbitMQ broker started on localhost:5672 configured with the default + * guest | guest client credentials on the / vHost. When a drink order + * is placed on the cold-drinks queue, the Barista will prepare the drink + * and reply to the reply-to queue set by the sender. + *

+ * The relevant components are defined within the configuration files: + * ("cafeDemo-amqp-baristaCold-xml.xml", "cafeDemo-amqp-config-xml.xml"). + *

+ * If deploying in SpringSource dmServer, the relevant ApplicationContext + * configuration is in the META-INF/spring directory instead. + * + * @author Tom McCuch + */ +public class CafeDemoAppBaristaColdAmqp { + + public static void main(String[] args) { + AbstractApplicationContext context = + new ClassPathXmlApplicationContext( + "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml", + CafeDemoAppBaristaColdAmqp.class); + + System.out.println("Press Enter/Return in the console to exit the Barista Cold App"); + try { + System.in.read(); + } catch (IOException e) { + context.close(); + } + context.close(); + } +} diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java new file mode 100644 index 00000000..0f0d8d9c --- /dev/null +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java @@ -0,0 +1,59 @@ +/* + * Copyright 2002-2011 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.cafe.xml; + +import java.io.IOException; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; + +/** + * Provides the 'main' method for running the Cafe Demo Hot Drink + * Barista application using AMQP. Before running, be sure to have a + * RabbitMQ broker started on localhost:5672 configured with the default + * guest | guest client credentials on the / vHost. When a drink order + * is placed on the hot-drinks queue, the Barista will prepare the drink + * and reply to the reply-to queue set by the sender. + *

+ * The relevant components are defined within the configuration files: + * ("cafeDemo-amqp-baristaHot-xml.xml", "cafeDemo-amqp-config-xml.xml"). + *

+ * If deploying in SpringSource dmServer, the relevant ApplicationContext + * configuration is in the META-INF/spring directory instead. + * + * @author Tom McCuch + */ +public class CafeDemoAppBaristaHotAmqp { + + public static void main(String[] args) { + AbstractApplicationContext context = + new ClassPathXmlApplicationContext( + "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml", + CafeDemoAppBaristaHotAmqp.class); + + System.out.println("Press Enter/Return in the console to exit the Barista Hot App"); + try { + System.in.read(); + } catch (IOException e) { + context.close(); + } + context.close(); + } +} diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java new file mode 100644 index 00000000..ec894dc8 --- /dev/null +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java @@ -0,0 +1,65 @@ +/* + * Copyright 2002-2011 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.cafe.xml; + +import java.io.IOException; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; + +/** + * Provides the 'main' method for running the Cafe Demo Operations + * application using AMQP. Before running, be sure to have a RabbitMQ + * broker started on localhost:5672 configured with the default + * guest | guest client credentials on the / vHost. When an order is + * placed on the new-orders queue, the Cafe Operations app will split + * the order into order line items, route them to either the coldDrink + * or hotDrink Barista, aggregate the prepared drinks returned from the + * Barista using a Waiter, and publish the delivered order on the + * cafe-deliveries exchange. + *

+ * The relevant components are defined within the configuration files: + * ("cafeDemo-amqp-operations-xml.xml", "cafeDemo-amqp-config-xml.xml"). + *

+ * Before starting this app, be sure to start the CafeDemoAppBaristaCold + * and CafeDemoAppBaristaHot apps first. + * + * If deploying in SpringSource dmServer, the relevant ApplicationContext + * configuration is in the META-INF/spring directory instead. + * + * @author Tom McCuch + */ +public class CafeDemoAppOperationsAmqp { + + public static void main(String[] args) { + AbstractApplicationContext context = + new ClassPathXmlApplicationContext( + "/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml", + CafeDemoAppOperationsAmqp.class); + + System.out.println("Press Enter/Return in the console to exit the Cafe Operations App"); + try { + System.in.read(); + } catch (IOException e) { + context.close(); + } + context.close(); + } +} diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml index ed990516..517fd70f 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml @@ -20,6 +20,9 @@ http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"> + + + - - - - - - - - - - - - - - + diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml index 6ff636a6..ea48b719 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml @@ -20,6 +20,9 @@ http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"> + + + - - - - - - - - - - - - - - - + diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml new file mode 100644 index 00000000..2613cf8f --- /dev/null +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml new file mode 100644 index 00000000..d8bbcbc8 --- /dev/null +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml index b5472278..b4c8feef 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml @@ -19,114 +19,37 @@ http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"> - - - - + + - + + - - - + + + + + + + - - - + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - - - - - - - - - - - - + \ No newline at end of file From b777bb46af26e77a140cbda7d8d445a50b17c0e7 Mon Sep 17 00:00:00 2001 From: Tom McCuch Date: Tue, 8 Nov 2011 09:04:35 -0500 Subject: [PATCH 4/7] fixed breakage --- .../org/springframework/integration/samples/cafe/Cafe.java | 2 +- .../spring/integration/amqp/cafeDemo-amqp-operations-xml.xml | 4 ++-- .../META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java index fecbce4d..66363ca8 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Cafe.java @@ -30,7 +30,7 @@ import org.springframework.integration.annotation.Gateway; */ public interface Cafe { - @Gateway(requestChannel="preOrders") + @Gateway(requestChannel="orders") void placeOrder(Order order); } diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml index d8bbcbc8..535bb351 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml @@ -27,9 +27,9 @@ - + - + diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml index b4c8feef..fd000aa7 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml @@ -25,9 +25,9 @@ - + - + From 5e13691d2d59e908abc51ae1b59aa370def7c2a7 Mon Sep 17 00:00:00 2001 From: Tom McCuch Date: Tue, 8 Nov 2011 09:27:17 -0500 Subject: [PATCH 5/7] updated readme --- applications/cafe/readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/cafe/readme.txt b/applications/cafe/readme.txt index a0c3f488..baee0e61 100644 --- a/applications/cafe/readme.txt +++ b/applications/cafe/readme.txt @@ -37,8 +37,8 @@ Instructions for running the CafeDemo sample 1. cafeDemoAppBaristaColdAmqp - starts the Cold Drink Barista 2. cafeDemoAppBaristaHotAmqp- starts the Hot Drink Barista - 3. cafeDemoAppOperationsAmqp - starts the Cafe Operations (OrderSplitter, DrinkRouter, PreparedDrinkAggregator) - 4. cafeDemoAppAmqp - starts the Cafe Storefront (Places 100 orders on the orders queue) + 3. cafeDemoAppAmqp - starts the Cafe Storefront (Places 100 orders on the orders queue) + 4. cafeDemoAppOperationsAmqp - starts the Cafe Operations (OrderSplitter, DrinkRouter, PreparedDrinkAggregator) * Note: All AMQP exchanges, queues, and bindings needed for this sample are defined within the different xml config files that support the above test classes. From 3db74937466d565b1f2e6be0341a041c3a955cd1 Mon Sep 17 00:00:00 2001 From: Joe Freeman Date: Wed, 16 Nov 2011 06:26:02 -0500 Subject: [PATCH 6/7] added comments --- .../integration/samples/cafe/Order.java | 1 + .../integration/samples/cafe/OrderItem.java | 1 + .../amqp/cafeDemo-amqp-baristaCold-xml.xml | 1 + .../integration/amqp/cafeDemo-amqp-baristaHot-xml.xml | 1 + .../integration/amqp/cafeDemo-amqp-config-xml.xml | 11 ++++++++++- .../integration/amqp/cafeDemo-amqp-operations-xml.xml | 7 ++++++- .../spring/integration/amqp/cafeDemo-amqp-xml.xml | 1 + .../META-INF/spring/integration/cafeDemo-xml.xml | 5 +++++ 8 files changed, 26 insertions(+), 2 deletions(-) diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java index 448d7186..6f836a82 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/Order.java @@ -28,6 +28,7 @@ public class Order { private List orderItems = new ArrayList(); + /** the order number used for tracking */ private int number; // Default constructor required by Jackson Java JSON-processor diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java index d256bd81..c3e0a2b0 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/OrderItem.java @@ -29,6 +29,7 @@ public class OrderItem { private boolean iced = false; + /** the order this item is tied to */ private int orderNumber; // Default constructor required by Jackson Java JSON-processor diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml index 517fd70f..1f9fc98f 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml @@ -23,6 +23,7 @@ + + + + + + - + + + diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml index 535bb351..6235a8e6 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml @@ -22,9 +22,11 @@ + + @@ -49,7 +51,8 @@ - + + + + + + + + + + From 32e38d09d2848f0692efa7d3fac8da84cf56deaf Mon Sep 17 00:00:00 2001 From: Joe Freeman Date: Wed, 16 Nov 2011 13:07:22 -0500 Subject: [PATCH 7/7] converted to spring 3.1 to support profiles --- applications/cafe/pom.xml | 11 +++++ .../samples/cafe/xml/CafeDemoAppAmqp.java | 23 ++++++--- .../cafe/xml/CafeDemoAppBaristaColdAmqp.java | 4 +- .../cafe/xml/CafeDemoAppBaristaHotAmqp.java | 4 +- .../cafe/xml/CafeDemoAppOperationsAmqp.java | 4 +- .../cafe/xml/CafeDemoAppUtilities.java | 36 ++++++++++++++ .../amqp/cafeDemo-amqp-config-xml.xml | 47 +++++++++++-------- 7 files changed, 96 insertions(+), 33 deletions(-) create mode 100644 applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppUtilities.java diff --git a/applications/cafe/pom.xml b/applications/cafe/pom.xml index b0483d22..a823958b 100644 --- a/applications/cafe/pom.xml +++ b/applications/cafe/pom.xml @@ -8,10 +8,21 @@ Spring Integration Cafe Sample 2.1.0.M3 + 3.1.0.RC1 1.2.16 4.7 + + org.springframework + spring-tx + ${spring.core.version} + + + org.springframework + spring-context + ${spring.core.version} + org.springframework.integration spring-integration-amqp diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java index db802315..4d259852 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppAmqp.java @@ -38,12 +38,14 @@ import org.springframework.integration.samples.cafe.Order; * * @author Tom McCuch */ -public class CafeDemoAppAmqp { - - public static void main(String[] args) { - AbstractApplicationContext context = - new ClassPathXmlApplicationContext("/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml", CafeDemoAppAmqp.class); - +public class CafeDemoAppAmqp { + + /** + * place some orders + * @param context spring context + * @param count the number of standard orders + */ + public static void order(AbstractApplicationContext context, int count){ Cafe cafe = (Cafe) context.getBean("cafe"); for (int i = 1; i <= 100; i++) { Order order = new Order(i); @@ -51,7 +53,14 @@ public class CafeDemoAppAmqp { order.addItem(DrinkType.MOCHA, 3, true); cafe.placeOrder(order); } - + } + + public static void main(String[] args) { + AbstractApplicationContext context = + CafeDemoAppUtilities.loadProfileContext( + "/META-INF/spring/integration/amqp/cafeDemo-amqp-xml.xml", + CafeDemoAppAmqp.class,CafeDemoAppUtilities.DEV); + order(context, 100); context.close(); } } diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java index bde92220..2fa94d32 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaColdAmqp.java @@ -44,9 +44,9 @@ public class CafeDemoAppBaristaColdAmqp { public static void main(String[] args) { AbstractApplicationContext context = - new ClassPathXmlApplicationContext( + CafeDemoAppUtilities.loadProfileContext( "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaCold-xml.xml", - CafeDemoAppBaristaColdAmqp.class); + CafeDemoAppBaristaColdAmqp.class,CafeDemoAppUtilities.DEV); System.out.println("Press Enter/Return in the console to exit the Barista Cold App"); try { diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java index 0f0d8d9c..0d37cad6 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppBaristaHotAmqp.java @@ -44,9 +44,9 @@ public class CafeDemoAppBaristaHotAmqp { public static void main(String[] args) { AbstractApplicationContext context = - new ClassPathXmlApplicationContext( + CafeDemoAppUtilities.loadProfileContext( "/META-INF/spring/integration/amqp/cafeDemo-amqp-baristaHot-xml.xml", - CafeDemoAppBaristaHotAmqp.class); + CafeDemoAppBaristaHotAmqp.class,CafeDemoAppUtilities.DEV); System.out.println("Press Enter/Return in the console to exit the Barista Hot App"); try { diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java index ec894dc8..f2246647 100644 --- a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppOperationsAmqp.java @@ -50,9 +50,9 @@ public class CafeDemoAppOperationsAmqp { public static void main(String[] args) { AbstractApplicationContext context = - new ClassPathXmlApplicationContext( + CafeDemoAppUtilities.loadProfileContext( "/META-INF/spring/integration/amqp/cafeDemo-amqp-operations-xml.xml", - CafeDemoAppOperationsAmqp.class); + CafeDemoAppOperationsAmqp.class,CafeDemoAppUtilities.DEV); System.out.println("Press Enter/Return in the console to exit the Cafe Operations App"); try { diff --git a/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppUtilities.java b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppUtilities.java new file mode 100644 index 00000000..6eac278f --- /dev/null +++ b/applications/cafe/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppUtilities.java @@ -0,0 +1,36 @@ +package org.springframework.integration.samples.cafe.xml; + +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.GenericXmlApplicationContext; +import org.springframework.integration.samples.cafe.Cafe; +import org.springframework.integration.samples.cafe.DrinkType; +import org.springframework.integration.samples.cafe.Order; + +public class CafeDemoAppUtilities { + + /** spring profile for running locally */ + public static final String DEV = "dev"; + /** spring profile for running in cloud foundry */ + public static final String CLOUD = "cloud"; + + + /** + * + * @param path path to the file + * @param targetClass the class who's classloader we will use to laod the context file + * @param profile a profile name + * @return the spring context + */ + public static AbstractApplicationContext loadProfileContext(String path, Class targetClass, String profile) { + GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); + ctx.getEnvironment().setActiveProfiles(profile); + ctx.setClassLoader(targetClass.getClassLoader()); + ctx.load(path); + ctx.refresh(); + return ctx; + } + + + + +} diff --git a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml index cd82b341..3ac623d0 100644 --- a/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml +++ b/applications/cafe/src/main/resources/META-INF/spring/integration/amqp/cafeDemo-amqp-config-xml.xml @@ -1,32 +1,39 @@ - - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + +