我在spring application.yml文件中定义了一组时间表,如下所示:
reports:
reportPaths:
11: "\\\\path\\pnl\\"
10: "\\\\path\\balance\\"
schedule-1:
description: Deliver pnl files
report: 11
format: PDF
cron: '0 00 17* * *'
schedule-2:
description: Deliver balance sheet files
report: 10
format: PDF
cron: '0 00 16* * *'在不同的时间在服务器上创建不同的文件类型。我的应用程序希望按照cron计划发送报告。
我登记和安排工作如下:
threadPoolTaskScheduler.schedule(new Job(schedule), new CronTrigger(environment.getProperty(schedule + ".cron")));职业类别:
public class Job implements Runnable {
private String job;
public ScheduledJobRouter(String job) {
this.job= job;
}
@Override
public void run() {
logger.info("Running Report job'{}' ({})", job);
}
}我的问题是,由于我正在处理发送给订阅者的每个报表类型的多目录,如何根据与spring-integration的计划启动集成工作流。例如,在16:00 hrs:.文件的计划时间,FileReadingMessageSource`‘读取报表10的目录
17:00,FileReadingMessageSource读取报表11的目录。
如何为我在预定时间处理的多个目录初始化FileReadingMessageSource。是否必须为所处理的每个报表目录定义多个bean?
也许,这个框架为处理这种情况提供了更好的选择?
发布于 2017-09-25 16:26:38
可以在每次投票之前或之后使用智能轮询器重新配置MessageSource。
编辑
@SpringBootApplication
public class So46409658Application {
public static void main(String[] args) {
SpringApplication.run(So46409658Application.class, args);
}
@Value("reports.reportPaths.10")
private String ten;
@Value("reports.reportPaths.11")
private String eleven;
@Bean
@InboundChannelAdapter(channel = "foo", poller = @Poller("poller"))
public MessageSource<File> frms() {
new File(this.ten).mkdirs();
new File(this.eleven).mkdirs();
FileReadingMessageSource source = new FileReadingMessageSource();
source.setDirectory(new File(this.ten));
return source;
}
@Bean
public PollerMetadata poller() {
PollerMetadata poller = new PollerMetadata();
poller.setTrigger(new PeriodicTrigger(5000));
poller.setAdviceChain(Arrays.asList(advice()));
return poller;
}
public AbstractMessageSourceAdvice advice() {
return new AbstractMessageSourceAdvice() {
private volatile boolean swap;
@Override
public boolean beforeReceive(MessageSource<?> source) {
File directory = new File(this.swap ? eleven : ten);
((FileReadingMessageSource) source).setDirectory(directory);
swap = !swap;
System.out.println("Polling " + directory);
return true;
}
@Override
public Message<?> afterReceive(Message<?> result, MessageSource<?> source) {
return result;
}
};
}
}如果使用的是XML配置,请将通知链添加到<poller/>中。
https://stackoverflow.com/questions/46409658
复制相似问题