我们被要求为文件夹中的报告文件编制索引。我们需要分批索引,这意味着如果我们没有足够的文件我们不会索引。但是,即使经过一定时间后我们没有足够的文件,我们最终也会建立索引。所以我们有这两个触发相同功能的条件。
我们已经能够正确配置队列、入站轮询器(用于获取文件)和出站轮询器(用于在 x 时间过去后索引文件)。但是,当队列已满时,我们仍然无法触发该功能。而且,即使我承认我们远不是 Spring 集成方面的专家,但当我说我们已经多次阅读文档并看到无数示例项目时,请相信我。但这仍然是我们无法企及的。
话够多了。在这里,有一些代码:
ip 客户报告配置:
<?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"
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">
<bean id="customerReportsFileManager" class="xxx.xxx.xxx.xxx.reports.CustomerReportsFileManager" />
<int:channel id="customerReportInputChannel" />
<int-file:inbound-channel-adapter channel="customerReportInputChannel" directory="${customer.reports.directory}">
<int:poller time-unit="SECONDS" fixed-delay="3" />
</int-file:inbound-channel-adapter>
<int:service-activator input-channel="customerReportInputChannel" output-channel="customerReportIndexationInputChannel"
ref="customerReportsFileManager" method="prepareFile" />
<int:channel id="customerReportIndexationInputChannel">
<int:queue capacity="3" /> <!-- Capacity -1 -->
</int:channel>
<int:outbound-channel-adapter channel="customerReportIndexationInputChannel" ref="customerReportsFileManager" method="indexReports">
<int:poller time-unit="SECONDS" fixed-delay="60" />
</int:outbound-channel-adapter>
</beans>
客户报告文件管理器:
public class CustomerReportsFileManager {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerReportsFileManager.class);
public File prepareFile(File file) {
LOGGER.warn("[prepareFile] " + file.getPath());
return file;
}
public void indexReports(File file) {
LOGGER.warn("[indexReports] " + file.getPath());
}
}