Spring Integration Channels-Direct channel :Lab-3
The only difference b/w Pollable and Direct channel is , There will not be any queue size limit in Direct channel
<int:channel id=”messageChannel” />
Everything else will remain same as with pollable channel.
spring-integration-channels.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:int="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int-stream="http://www.springframework.org/schema/integration/stream" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"> <!-- message producer / a Spring Integration wrapped Java Standard input stream --> <int-stream:stdin-channel-adapter id="producer" channel="messageChannel" /> <!-- a pair of message consumers / a pair of Spring Integration wrapped Java Standard output streams --> <int-stream:stdout-channel-adapter id="consumer1" channel="messageChannel" append-newline="true" /> <int-stream:stdout-channel-adapter id="consumer2" channel="messageChannel" append-newline="true" /> <int:poller id="defaultPoller" default="true" max-messages-per-poll="5" fixed-rate="200" /> <!-- a pub/sub message channel --> <!--<int:publish-subscribe-channel id="messageChannel" />--> <int:channel id="messageChannel" > <!--<int:queue capacity="2"/>--> </int:channel></beans>
Main container loader class which will load all the beans
Startup.java
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Startup { @SuppressWarnings({ "resource", "unused" }) // @SuppressWarnings({ "resource" }) public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/si-components.xml"); while (true) { } }}
Retest the application. With the pollable channel in place of the subscribable
channel, rerun the application.
The application is now running awaiting your text input. In the Console view, again
enter some text and then hit the Enter key. A text message created from the text you enter
into the Standard Input will immediately be marshalled into the direct channel. Notice how
the message is only delivered to a single (the first) consumer of the messages (like a pollable
channel but without a queue!). Note that the text is only echoed one time.
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Contanier started…..
Deepak
Deepak
Garv
Garv
Source code can be found in below GIT repository