The spring integration hello word sample demonstrate the use of inbound-channel-adapter.
I have extended the demo to have 2 inbounds channels adapters:
The spring integration context description file:
<?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.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:task="http://www.springframework.org/schema/task">
<int:inbound-channel-adapter id="currentTimeMillis" expression="T(java.lang.System).currentTimeMillis()" channel="logger">
<int:poller fixed-delay="10000" max-messages-per-poll="2" />
</int:inbound-channel-adapter>
<int:inbound-channel-adapter id="Counter"
expression="T(org.springframework.integration.samples.helloworld.myCounter).Count" channel="logger">
<int:poller fixed-delay="10000" max-messages-per-poll="1" />
</int:inbound-channel-adapter>
<int:logging-channel-adapter id="logger" logger-name="org.springframework.integration.samples.helloworld"/>
<task:executor id="executor" queue-capacity="20" pool-size="5-20"/>
</beans>
I add a new inbound-channel-adapter that its source is from the class myCounter:
package org.springframework.integration.samples.helloworld;
public class myCounter {
private static int mCount;
static public int getCount()
{
mCount ++;
return mCount;
}
}
Apoller is defined to trigger the channel execution every 10Sec.
Notes:
When the spring context is loaded using the new ClassPathXmlApplicationContext("META-INF/spring/integration/delay.xml"); The task:executor is responsible to start the execution of the inbound-channel-adapters declared on the spring context .
The output channel is of type:int:logging-channel-adapter this channel get as parameter a reference to location of log4j xml file.
and the results:
16:02:24.694 INFO [task-scheduler-2][org.springframework.integration.samples.helloworld] 1
16:02:24.694 INFO [task-scheduler-1][org.springframework.integration.samples.helloworld] 1369141344643
16:02:24.696 INFO [task-scheduler-1][org.springframework.integration.samples.helloworld] 1369141344695
16:02:34.696 INFO [task-scheduler-2][org.springframework.integration.samples.helloworld] 2
16:02:34.696 INFO [task-scheduler-1][org.springframework.integration.samples.helloworld] 1369141354696
16:02:34.697 INFO [task-scheduler-1][org.springframework.integration.samples.helloworld] 1369141354697
16:02:44.698 INFO [task-scheduler-4][org.springframework.integration.samples.helloworld] 3
16:02:44.699 INFO [task-scheduler-3][org.springframework.integration.samples.helloworld] 1369141364699
16:02:44.700 INFO [task-scheduler-3][org.springframework.integration.samples.helloworld] 1369141364700
16:02:54.700 INFO [task-scheduler-4][org.springframework.integration.samples.helloworld] 4
16:02:54.701 INFO [task-scheduler-4][org.springframework.integration.samples.helloworld] 1369141374701
16:02:54.702 INFO [task-scheduler-4][org.springframework.integration.samples.helloworld] 1369141374702
------------------------------------------------------------------------
אין תגובות:
הוסף רשומת תגובה