Add demo for outbound ip adapter - loanshark Roo App receives data.

This commit is contained in:
Gary Russell
2010-03-29 20:05:07 +00:00
parent 353bbc7fd1
commit fee52f0eef
7 changed files with 143 additions and 1 deletions

View File

@@ -10,6 +10,11 @@
<artifactId>org.springframework.integration</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>org.springframework.integration.ip</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.spring-library</artifactId>

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2002-2010 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.loanbroker;
import org.springframework.integration.loanbroker.domain.LoanQuote;
/**
* @author Gary Russell
*
*/
public class Transformer {
public String transformShark(LoanQuote quote) {
return quote.getLender() + "," + quote.getRate();
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<import resource="classpath:stub-services-config.xml" />
<import resource="classpath:loan-broker-config.xml" />
<import resource="classpath:bank-channel-mappings-config.xml" />
<import resource="classpath:shark-detector-config.xml"/>
</beans>

View File

@@ -0,0 +1,40 @@
<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip-2.0.xsd">
<int:channel id="quotesAggregationChannel">
<int:interceptors>
<int:wire-tap channel="loanSharkDetectorChannel"/>
</int:interceptors>
</int:channel>
<int:channel id="loanSharkDetectorChannel" />
<int:filter id="loanSharkFilter"
input-channel="loanSharkDetectorChannel"
output-channel="loanSharkChannel"
expression="payload.rate > 5.2"/>
<int:channel id="loanSharkChannel" />
<int:transformer ref="udpTransformer"
input-channel="loanSharkChannel"
output-channel="sharkOutChannel"/>
<bean id="udpTransformer" class="org.springframework.integration.loanbroker.Transformer"/>
<int:channel id="sharkOutChannel" />
<int-ip:outbound-channel-adapter id="udpOut"
channel="sharkOutChannel"
protocol="udp"
host="225.6.7.8"
multicast="true"
port="11111"/>
</beans>

View File

@@ -46,7 +46,7 @@ public class LoanBrokerDemo {
public void runDemo() {
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("bootstrap-config/stubed-loan-broker.xml");
new ClassPathXmlApplicationContext("bootstrap-config/stubbed-loan-broker.xml");
LoanBrokerGateway broker = ac.getBean("loanBrokerGateway", LoanBrokerGateway.class);
LoanRequest loanRequest = new LoanRequest();

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2002-2010 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.loanbroker.demo;
import java.util.List;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.loanbroker.LoanBrokerGateway;
import org.springframework.integration.loanbroker.domain.Customer;
import org.springframework.integration.loanbroker.domain.LoanQuote;
import org.springframework.integration.loanbroker.domain.LoanRequest;
/**
* @author Gary Russell
*
*/
public class LoanBrokerSharkDetectorDemo {
private static Logger logger = Logger.getLogger(LoanBrokerSharkDetectorDemo.class);
@Test
public void testUdpMulticast() {
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("bootstrap-config/stubbed-loan-broker-multicast.xml");
LoanBrokerGateway broker = ac.getBean("loanBrokerGateway", LoanBrokerGateway.class);
LoanRequest loanRequest = new LoanRequest();
loanRequest.setCustomer(new Customer());
LoanQuote loan = broker.getLoanQuote(loanRequest);
logger.info("\n********* Best Quote: " + loan);
List<LoanQuote> loanQuotes = broker.getAllLoanQuotes(loanRequest);
logger.info("\n********* All Quotes: ");
for (LoanQuote loanQuote : loanQuotes) {
logger.info(loanQuote);
}
ac.close();
}
}