檔案聚合器
從版本 5.5 開始,引入了 FileAggregator,用於在啟用 START/END 標記時處理 FileSplitter 用例的另一面。為方便起見,FileAggregator 實現了所有三種序列詳細資訊策略。
-
HeaderAttributeCorrelationStrategy和FileHeaders.FILENAME屬性用於關聯鍵計算。當FileSplitter啟用標記時,它不會填充序列詳細資訊頭,因為 START/END 標記訊息也包含在序列大小中。FileHeaders.FILENAME仍會為發出的每一行(包括 START/END 標記訊息)填充。 -
FileMarkerReleaseStrategy- 檢查組中是否存在FileSplitter.FileMarker.Mark.END訊息,然後將FileHeaders.LINE_COUNT頭值與組大小減去2(即FileSplitter.FileMarker例項) 進行比較。它還為conditionSupplier函式實現了方便的GroupConditionProvider契約,可在AbstractCorrelatingMessageHandler中使用。有關更多資訊,請參閱 訊息組條件。 -
FileAggregatingMessageGroupProcessor只是從組中移除FileSplitter.FileMarker訊息,並將剩餘訊息收集到列表中作為有效負載進行生成。
以下列表顯示了配置 FileAggregator 的可能方法:
-
Java DSL
-
Kotlin DSL
-
Java
-
XML
@Bean
public IntegrationFlow fileSplitterAggregatorFlow(TaskExecutor taskExecutor) {
return f -> f
.split(Files.splitter()
.markers()
.firstLineAsHeader("firstLine"))
.channel(c -> c.executor(taskExecutor))
.filter(payload -> !(payload instanceof FileSplitter.FileMarker),
e -> e.discardChannel("aggregatorChannel"))
.<String, String>transform(String::toUpperCase)
.channel("aggregatorChannel")
.aggregate(new FileAggregator())
.channel(c -> c.queue("resultChannel"));
}
@Bean
fun fileSplitterAggregatorFlow(taskExecutor: TaskExecutor?) =
integrationFlow {
split(Files.splitter().markers().firstLineAsHeader("firstLine"))
channel { executor(taskExecutor) }
filter<Any>({ it !is FileMarker }) { discardChannel("aggregatorChannel") }
transform(String::toUpperCase)
channel("aggregatorChannel")
aggregate(FileAggregator())
channel { queue("resultChannel") }
}
@serviceActivator(inputChannel="toAggregateFile")
@Bean
public AggregatorFactoryBean fileAggregator() {
AggregatorFactoryBean aggregator = new AggregatorFactoryBean();
aggregator.setProcessorBean(new FileAggregator());
aggregator.setOutputChannel(outputChannel);
return aggregator;
}
<int:chain input-channel="input" output-channel="output">
<int-file:splitter markers="true"/>
<int:aggregator>
<bean class="org.springframework.integration.file.aggregator.FileAggregator"/>
</int:aggregator>
</int:chain>
如果 FileAggregator 的預設行為不滿足目標邏輯,建議使用單獨的策略配置聚合器端點。有關更多資訊,請參閱 FileAggregator JavaDocs。