- 我有凡在我需要從MQ隊列中接收的一系列消息的,寫這一個文件,並啓動春季批處理作業與文件作爲輸入問題
一這樣做,這將是搞了一下Spring集成,在這裏你將有一個文件輪詢,那將輪詢新文件:
<file:inbound-channel-adapter id="filePoller"
channel="filesAreComing"
directory="file:${input.directory}"
filename-pattern="test*" />
適應file message
(java.io.File中)到file name
(字符串),因爲這是Spring Batch需要的。這可以用JobLauncher適配器來完成,這是已經可以從Spring Batch的聯繫here:
@ServiceActivator
public JobLaunchRequest adapt(File file) throws NoSuchJobException {
JobParameters jobParameters = new JobParametersBuilder().addString(
"input.file", file.getAbsolutePath()).toJobParameters();
return new JobLaunchRequest(job, jobParameters);
}
它換到一個JobLaunchRequest
(這僅僅是一個Job
和JobParameters
持有人),併發送該請求[作爲消息]到JobLaunchingMessageHandler
:
<service-activator input-channel="jobLauncher">
<beans:bean class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">
<beans:constructor-arg ref="jobLauncher" />
</beans:bean>
</service-activator>
,將啓動作業。
「input.file」 是在運行時(因此#{...})約束的參數:
<bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="#{jobParameters[input.file]}" />
... line mapper and other props
</bean>
感謝您挖掘這個問題。我已經實現了你的建議(http://stackoverflow.com/questions/7152467/spring-serviceactivator - 即使這個問題已解決,只是我懶得更新答案)。不過謝謝你的努力。 – nobody
感覺很棒幫助@nobody :) [當然,歡迎!] – tolitius
服務激活器可能需要一個output-channel =「nullChannel」屬性來處理響應消息 –