等待jdbc出站通道适配器完成,然后再进一步处理
我是Spring集成的新手,我正在一个小项目中试验各种组件 在手头的任务中,我需要处理一个文本文件并将其内容存储到数据库中。该文件包含可以分组在一起的行,因此很自然地将每个文件划分为几个独立的消息 这是整个过程(请参阅最后的配置):等待jdbc出站通道适配器完成,然后再进一步处理,jdbc,spring-integration,Jdbc,Spring Integration,我是Spring集成的新手,我正在一个小项目中试验各种组件 在手头的任务中,我需要处理一个文本文件并将其内容存储到数据库中。该文件包含可以分组在一起的行,因此很自然地将每个文件划分为几个独立的消息 这是整个过程(请参阅最后的配置): 进行初步的文件分析; 由变压器完成。输出变压器 将一些数据存储到数据库(即文件名、文件日期等); ? 将文件内容拆分为几个不同的消息; 由拆分器完成。结果拆分器 进一步分析每条信息; 由变压器完成。SingleoutcomeToMap 将单个消息数据
- 由变压器完成。输出变压器
- ?
- 由拆分器完成。结果拆分器
- 由变压器完成。SingleoutcomeToMap
- 由存储过程出站通道适配器完成
- T1表示文件元数据(文件名、文件日期、文件源等)李>
- T2对于文件内容详细信息,此处的行引用T1中的行
TaskExecutor
),将jdbc出站适配器作为第一个订户,将stem 3中的拆分器作为第二个订户:然后每个订阅的处理程序都应该接收消息的副本,但我不清楚拆分器中的任何处理是否会等待出站适配器完成
这是完成任务的正确方法吗?如果异步调用第4步中的转换器会怎么样?每个拆分的消息都是自包含的,这将需要并发性
弹簧配置:
你的想法是正确的。当您有一个
PublishSubscribeChannel
而没有执行器时,下一个订阅者将在上一个订阅者完成其工作时等待。因此,在DB上完成所有操作之前,不会调用您的splllitt
。默认情况下,当第一个订户无法处理消息(不是DB连接?)时,将不会调用所有其他订户
另一种实现类似行为的方法可以通过
和表达式evaluationRequestHandlerAdvice配置:
所有拆分器下游流并发和多线程已经与DB逻辑无关。在DB正确执行其请求之前,不会发生并行性
<?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-file="http://www.springframework.org/schema/integration/file"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns:beans="http://www.springframework.org/schema/beans"
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/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/integration/jdbc
http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- input-files-from-folder -->
<int-file:inbound-channel-adapter id="outcomeIn"
directory="file:/in-outcome">
<int:poller id="poller" fixed-delay="2500" />
</int-file:inbound-channel-adapter>
<int:transformer input-channel="outcomeIn" output-channel="outcomesChannel" method="transform">
<beans:bean class="transformers.outcomeTransf" />
</int:transformer>
<!-- save source to db! -->
<int:splitter input-channel="outcomesChannel" output-channel="singleoutcomeChannel" method="splitMessage">
<beans:bean class="splitters.outcomeSplit" />
</int:splitter>
<int:transformer input-channel="singleoutcomeChannel" output-channel="jdbcChannel" method="transform">
<beans:bean class="transformers.SingleoutcomeToMap" />
</int:transformer>
<int-jdbc:stored-proc-outbound-channel-adapter
data-source="dataSource" channel="jdbcChannel" stored-procedure-name="insert_outcome"
ignore-column-meta-data="true">
<int-jdbc:sql-parameter-definitions ... />
<int-jdbc:parameter ... />
</int-jdbc:stored-proc-outbound-channel-adapter>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close" >
<property name="driverClassName" value="org.postgresql.Driver"/>
<property ... />
</bean>
</beans>