spring poller执行器通道实现

时间:2015-11-26 07:32:01

标签: spring-integration

我的轮询器从数据库中获取数据后,我正在调用外部服务。 从该服务获得响应后,我想在一个单独的线程中调用另一个系统。意思是,在得到回复之后,我的轮询器应该再记录并发送。另外调用其他系统应该并行工作

为此,我使用直接通道从DB接收数据。使用服务激活器向外部服务发送请求。响应被传递给执行者channel.can任何人请告诉我下面的配置是否适用于该场景?

为清楚起见,我正在共享poller.xml



<?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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:task="http://www.springframework.org/schema/task" xmlns:int-http="http://www.springframework.org/schema/integration/http"
	xmlns: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/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration-4.1.xsd
            http://www.springframework.org/schema/integration/stream 
		http://www.springframework.org/schema/integration/stream/spring-integration-stream-4.1.xsd
               http://www.springframework.org/schema/integration/http
    http://www.springframework.org/schema/integration/http/spring-integration-http-4.1.xsd
            http://www.springframework.org/schema/integration/jdbc
            http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc-4.1.xsd
            http://www.springframework.org/schema/jdbc
            http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd">

	<!-- <import resource="persistence-config.xml" /> <int:channel id="inchannel"> 
		</int:channel> <int:channel id="outchannel"> <int:dispatcher task-executor="taskExecutor"/> 
		</int:channel> <task:executor id="taskExecutor" pool-size="2"/> <bean id="poller" 
		class="main.java.com.as.poller.PollerService" /> <int:service-activator input-channel="inchannel" 
		output-channel="outchannel" ref="poller" method="sendMessage" /> -->


	<int-jdbc:inbound-channel-adapter id="dataChannel"
		query="select loyalty_id, process_id,mobile_uid from TBL_RECEIPT where r_cre_time=(select min(r_cre_time) from TBL_RECEIPT where receipt_status=0)"
		data-source="dataSource" max-rows-per-poll="1"
		update="update TBL_RECEIPT set receipt_status=11 where loyalty_id in (:loyalty_id)">
		<int:poller fixed-rate="5000">
		</int:poller>
	</int-jdbc:inbound-channel-adapter>


	<bean id="poller" class="main.java.com.as.poller.PollerService" />
	
	<int:channel id="executerchannel">
	<int:dispatcher task-executor="taskExecutor"/> 
		</int:channel>
		
 <task:executor id="taskExecutor" pool-size="20"/>
	
	<int:service-activator input-channel="dataChannel"
		output-channel="executerchannel" ref="poller" method="processMessage" />
		
		<int:service-activator input-channel="executerchannel" ref="poller" method="processTpg">
		</int:service-activator>
		
		<stream:stdout-channel-adapter id="executerchannel"/>
		
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

没有;它不正确(几乎是正确的)。

<stream:stdout-channel-adapter id="executerchannel"/>

这会覆盖您的执行程序通道定义(没有channel属性的出站适配器会创建一个具有该ID的通道。)

您最终会得到一个简单的直接频道,其中包含2个订阅者(stdout和您的服务激活器) - 他们将获得备用消息。

我不确定你为什么要添加这个元素;将其删除或订阅其他频道。

如果你想要去两个地方;使用执行程序将频道更改为<publish-subscribe-channel/>