converted to spring 3.1 to support profiles
This commit is contained in:
@@ -8,10 +8,21 @@
|
||||
<name>Spring Integration Cafe Sample</name>
|
||||
<properties>
|
||||
<spring.integration.version>2.1.0.M3</spring.integration.version>
|
||||
<spring.core.version>3.1.0.RC1</spring.core.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<junit.version>4.7</junit.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<version>${spring.core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-amqp</artifactId>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,32 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xmlns:cloud="http://schema.cloudfoundry.org/spring"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xmlns:cloud="http://schema.cloudfoundry.org/spring"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://schema.cloudfoundry.org/spring
|
||||
http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd
|
||||
http://www.springframework.org/schema/rabbit
|
||||
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
|
||||
|
||||
<!-- Obtain a connection to the RabbitMQ via cloudfoundry-runtime: -->
|
||||
<!--
|
||||
<cloud:rabbit-connection-factory id="rabbitConnectionFactory"/>
|
||||
-->
|
||||
|
||||
<!-- connect to the local broker using the default user name and password -->
|
||||
<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
|
||||
<constructor-arg value="localhost"/>
|
||||
<property name="username" value="guest"/>
|
||||
<property name="password" value="guest"/>
|
||||
</bean>
|
||||
|
||||
<!-- Set up the AmqpTemplate/RabbitTemplate: -->
|
||||
<rabbit:template id="amqpTemplate" connection-factory="rabbitConnectionFactory" reply-timeout="10000"/>
|
||||
<rabbit:template id="amqpTemplate"
|
||||
connection-factory="rabbitConnectionFactory" reply-timeout="10000" />
|
||||
|
||||
<!-- Request that queues, exchanges and bindings be automatically
|
||||
declared on the broker: -->
|
||||
<rabbit:admin connection-factory="rabbitConnectionFactory" />
|
||||
<!-- Request that queues, exchanges and bindings be automatically declared
|
||||
on the broker: -->
|
||||
<rabbit:admin connection-factory="rabbitConnectionFactory" />
|
||||
|
||||
<!-- profiles must be the last element sin the file -->
|
||||
|
||||
<!-- Obtain a connection to the RabbitMQ via cloudfoundry-runtime: -->
|
||||
<beans profile="cloud">
|
||||
<cloud:rabbit-connection-factory
|
||||
id="rabbitConnectionFactory" />
|
||||
</beans>
|
||||
|
||||
<!-- connect to the local broker using the default user name and password -->
|
||||
<beans profile="dev">
|
||||
<bean id="rabbitConnectionFactory"
|
||||
class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
|
||||
<constructor-arg value="localhost" />
|
||||
<property name="username" value="guest" />
|
||||
<property name="password" value="guest" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user