INT-1716 added ControlBus sample

This commit is contained in:
Oleg Zhurakousky
2011-01-13 15:40:42 -05:00
parent f1e6daffc5
commit 7ac1924834
5 changed files with 85 additions and 2 deletions

View File

@@ -0,0 +1,3 @@
#Thu Jan 13 15:32:55 EST 2011
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/jmx/src/main/resources/META-INF/spring/integration/ControlBusDemo-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="513" endstart\="513" start\="479" startend\="513"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="586" endstart\="572" start\="517" startend\="555"/>\n<bounds height\="112" width\="116" x\="155" y\="149"/>\n</element>\n<element clazz\="ControlBusModelElement" type\="control-bus">\n<structure end\="638" endstart\="638" start\="589" startend\="638"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="860" endstart\="830" start\="642" startend\="794"/>\n<bounds height\="112" width\="116" x\="19" y\="149"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.3.3.201007151000-M2]]></pluginVersion>
<pluginVersion><![CDATA[2.5.2.201101121000-SR1]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/resources/META-INF/spring/integration/ControlBusDemo-context.xml</config>
</configs>
<configSets>
</configSets>

View File

@@ -1,6 +1,7 @@
This example demonstrates the following aspects of the JMX support available with Spring Integration:
1. JMX Attribute Polling Channel
2. JMX Operation Invoking Channel Adapter
3. Control Bus
StopWatch is a Managed Bean. It is bootstraped and deployed using annotation support (@Component, @ManagedResource)
and component scanning functionality provided by Spring JMX. Internally StopWatch simply runs a task that increments the
@@ -13,8 +14,10 @@ The interesting this is that 'seconds' channel is a publish-subscribe-channel an
Once the payload value is 10 filter sends the Message to a 'reset' channel which is represented as JMX Operation Invoking Channel Adapter
which simply invokes 'reset' operation on the same StopWatch MBean resetting 'Seconds' attribute value back to 1 and the process repeats.
Another example is a Control Bus which uses SpEL to send a Control Message to start/stop and inbound adapter
To run samples simply execute the 3 test cases located in the org.springframework.integration.samples.filecopy package
To run JMX Adapter sample simple execute JmxAdapterDemoTest
You will see the output similar to this which will loop for ~ 20 sec:
1
@@ -32,3 +35,11 @@ You will see the output similar to this which will loop for ~ 20 sec:
3
. . .
To run Control Bus sample simple execute ControlBusDemoTest
You will see the output similar to this
INFO : org.springframework.integration.samples.jmx.ControlBusDemo - Received before adapter started: null
INFO : org.springframework.integration.samples.jmx.ControlBusDemo - Received before adapter started: [Payload=Hello][Headers={timestamp=1294950897714, id=240e72fb-93b0-4d38-8fe8-b701cf7e9a5d}]
INFO : org.springframework.integration.samples.jmx.ControlBusDemo - Received after adapter stopped: null

View File

@@ -0,0 +1,22 @@
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<int:channel id="controlChannel"/>
<int:channel id="adapterOutputChanel">
<int:queue/>
</int:channel>
<int:control-bus input-channel="controlChannel"/>
<int:inbound-channel-adapter id="inboundAdapter"
channel="adapterOutputChanel"
expression="'Hello'"
auto-startup="false">
<int:poller fixed-rate="1000"/>
</int:inbound-channel-adapter>
</beans>

View File

@@ -0,0 +1,46 @@
/*
* 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.jmx;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.message.GenericMessage;
/**
* @author Oleg Zhurakousky
*
*/
public class ControlBusDemoTest {
private static Logger logger = Logger.getLogger(ControlBusDemoTest.class);
@Test
public void demoControlBus(){
ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/ControlBusDemo-context.xml");
MessageChannel controlChannel = ac.getBean("controlChannel", MessageChannel.class);
PollableChannel adapterOutputChanel = ac.getBean("adapterOutputChanel", PollableChannel.class);
logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
controlChannel.send(new GenericMessage<String>("@inboundAdapter.start()"));
logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
controlChannel.send(new GenericMessage<String>("@inboundAdapter.stop()"));
logger.info("Received after adapter stopped: " + adapterOutputChanel.receive(1000));
}
}