forked from spring-projects/spring-integration-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTSAMPLES-60 - Add JMS-backed Cafe Application Sample
* Add idea folder to .gitignore * Add an embedded ActiveMQ * Add activemq data to ignore list * Use JMS-backed channels * Add the sample description to README.md
- Loading branch information
1 parent
23ed55d
commit a46d0a3
Showing
50 changed files
with
746 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ derby.log | |
.idea | ||
activemq-data | ||
.settings/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Cafe Sample Application - AMQP Implementation | ||
======================= | ||
|
||
See the parent-level README.md for more details, but the flow of the implementation should follow this diagram: | ||
|
||
|
||
Barista | ||
hotDrinks ____________________ | ||
|==========| -->| | | ||
orders drinks / | prepareHotDrink() | | ||
Place Order ->Cafe->|======|->OrderSplitter->|======|->DrinkRouter | | | ||
\ coldDrinks | prepareColdDrink() | | ||
|==========| -->| | | ||
|____________________| | ||
|
||
Legend: |====| - channels | ||
|
||
|
||
## Instructions for running the CafeDemo AMQP sample | ||
|
||
### Distributed components | ||
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: | ||
|
||
1. **cafeDemoAppBaristaColdAmqp** - starts the Cold Drink Barista | ||
2. **cafeDemoAppBaristaHotAmqp** - starts the Hot Drink Barista | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>cafe</artifactId> | ||
<groupId>org.springframework.integration.samples</groupId> | ||
<version>2.1.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>cafe-amqp</artifactId> | ||
|
||
<name>Cafe - With AMQP Message Broker</name> | ||
<description> | ||
This module implements the cafe sample using spring-integration components backed | ||
by an AMQP message broker for message persistence and component distribution. This | ||
sample uses RabbitMQ broker, but any AMQP message broker can be used. For an example | ||
using JMS, see the JMS implemenation of the cafe sample. | ||
</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>cafe-si</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.integration</groupId> | ||
<artifactId>spring-integration-amqp</artifactId> | ||
<version>${spring.integration.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Cafe Sample Application - JMS Implementation | ||
======================= | ||
|
||
See the parent-level README.md for more details, but the flow of the implementation should follow this diagram: | ||
|
||
|
||
Barista | ||
hotDrinks ____________________ | ||
|==========| -->| | | ||
orders drinks / | prepareHotDrink() | | ||
Place Order ->Cafe->|======|->OrderSplitter->|======|->DrinkRouter | | | ||
\ coldDrinks | prepareColdDrink() | | ||
|==========| -->| | | ||
|____________________| | ||
Legend: |====| - channels | ||
|
||
|
||
## Instructions for running the CafeDemo JMS sample | ||
|
||
### Distributed components | ||
To run this configuration, start an instance of ActiveMQ with the openwire/TCP connector available on the default port (61616). There are no credentials of which to be aware. Please execute the following classes in order: | ||
|
||
1. **CafeDemoAppBaristaColdActiveMQ - starts the ColdDrink Barista | ||
2. **CafeDemoAppBaristaHotActiveMQ - starts the HotDrink Barista | ||
3. **CafeDemoAppOperationsActiveMQ - starts the Cafe Operations (order splitter, drink router, etc). | ||
4. **CafeDemoAppAcitveMQ - places the orders | ||
|
||
### JMS backed components | ||
|
||
See **CafeDemoActiveMQBackedChannels** for an example of how to use the JMS-backed channels. No need to start an external ActiveMQ because one is started internally |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.integration.samples</groupId> | ||
<artifactId>cafe</artifactId> | ||
<version>2.1.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>cafe-jms</artifactId> | ||
|
||
<name>Cafe - With JMS Message Broker</name> | ||
<description> | ||
This module implements the cafe sample using spring-integration components backed | ||
by a JMS broker for persistent messaging as well as component distribution. This | ||
sample uses ActiveMQ as the JMS broker, but any JMS-compliant broker can be | ||
used. For an example using AMQP, see the AMQP implementation of the cafe sample. | ||
</description> | ||
|
||
<properties> | ||
<activemq.version>5.4.3</activemq.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.activemq</groupId> | ||
<artifactId>activemq-all</artifactId> | ||
<version>${activemq.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.xbean</groupId> | ||
<artifactId>xbean-spring</artifactId> | ||
<version>3.9</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.integration</groupId> | ||
<artifactId>spring-integration-jms</artifactId> | ||
<version>${spring.integration.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>cafe-si</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
47 changes: 47 additions & 0 deletions
47
...java/org/springframework/integration/samples/cafe/xml/CafeDemoActiveMQBackedChannels.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Main class for running the Cafe sample with JMS-backed (ActiveMQ) channels. Once the application | ||
* is running, simply press <return> or any other key to end the application. To fully experience the | ||
* benefits of this solution, try halting/exiting the program in the middle of running it, comment out the | ||
* call to place new orders (the order() function call) and watch that the processing still continues | ||
* where it left off when you halted it. This is because the messages are persisted in the ActiveMQ queues | ||
* | ||
* @author ceposta | ||
*/ | ||
public class CafeDemoActiveMQBackedChannels { | ||
|
||
/** | ||
* 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 <= count; i++) { | ||
Order order = new Order(i); | ||
order.addItem(DrinkType.LATTE, 2, false); | ||
order.addItem(DrinkType.MOCHA, 3, true); | ||
cafe.placeOrder(order); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException, IOException { | ||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/activemq/cafeDemo-amq-config.xml", | ||
"/META-INF/spring/integration/activemq/cafeDemo-amq-jms-backed.xml"); | ||
|
||
// comment this out to run the sample without placing any new orders on the queue | ||
order(context, 25); | ||
|
||
System.in.read(); | ||
context.close(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...s/src/main/java/org/springframework/integration/samples/cafe/xml/CafeDemoAppActiveMQ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Main class for sending orders that will be handled in separate, distributed | ||
* processes. See the README.md file for more information on the order in which | ||
* to start the processes | ||
* | ||
* @author ceposta | ||
*/ | ||
public class CafeDemoAppActiveMQ { | ||
|
||
/** | ||
* 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 <= count; i++) { | ||
Order order = new Order(i); | ||
order.addItem(DrinkType.LATTE, 2, false); | ||
order.addItem(DrinkType.MOCHA, 3, true); | ||
cafe.placeOrder(order); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws InterruptedException, IOException { | ||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/activemq/cafeDemo-amq-config.xml", | ||
"/META-INF/spring/integration/activemq/cafeDemo-amq-xml.xml"); | ||
order(context, 25); | ||
context.close(); | ||
} | ||
} |
Oops, something went wrong.