主要应用:-
@SpringBootApplication
@Configuration
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder()
.web(false)
.sources(Application.class)
.run(args);
}
}
FilePollingIntegrationFlow 类:-
@Configuration
class FilePollingIntegrationFlow {
@Autowired
private ApplicationContext applicationContext;
//It does the file polling part:-
@Bean
public IntegrationFlow inboundFileIntegration(@Value("${inbound.file.poller.fixed.delay}") long period,
@Value("${inbound.file.poller.max.messages.per.poll}") int maxMessagesPerPoll,
TaskExecutor taskExecutor,
MessageSource < File > fileReadingMessageSource) {
// JobLaunchingGateway jobLaunchingGateway
return IntegrationFlows.from(fileReadingMessageSource,
c - > c.poller(Pollers.fixedDelay(period)
.taskExecutor(taskExecutor)
.maxMessagesPerPoll(maxMessagesPerPoll)))
.transform(Transformers.fileToString())
.channel(ApplicationConfiguration.INBOUND_CHANNEL)
.channel(MessageChannels.queue("fileReadingResultChannel"))
.get();
}
@Bean
TaskExecutor taskExecutor(@Value("${inbound.file.poller.thread.pool.size}") int poolSize) {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(poolSize);
return taskExecutor;
}
@Bean
public FileReadingMessageSource fileReadingMessageSource(@Value("${inbound.filename.regex}") String regex, @Value("${inbound.directory.location}") String directory) {
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File(directory));
source.setAutoCreateDirectory(true);
CompositeFileListFilter < File > filter = new CompositeFileListFilter < > (
Arrays.asList(new AcceptOnceFileListFilter < File > (),
new RegexPatternFileListFilter(regex))
);
source.setFilter(filter);
return source;
}
}
如何触发线程以一天中的固定时间(例如美国东部标准时间下午 5 点)检查系统时间,如果 sysyem 时间等于固定时间,则在使用 java dsl 和 spring boot 的 spring 集成项目中 System.exit(1)。
我想不通
- 如何退出 Integrationflows 并转移到另一个程序或方法。
- 运行一个单独的线程或在同一个线程之上运行轮询以实现我的功能。
请指教。