首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >处理多个目录和计划--春季集成

处理多个目录和计划--春季集成
EN

Stack Overflow用户
提问于 2017-09-25 16:10:47
回答 1查看 1K关注 0票数 1

我在spring application.yml文件中定义了一组时间表,如下所示:

代码语言:javascript
复制
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计划发送报告。

我登记和安排工作如下:

代码语言:javascript
复制
threadPoolTaskScheduler.schedule(new Job(schedule), new CronTrigger(environment.getProperty(schedule + ".cron")));

职业类别:

代码语言:javascript
复制
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?

也许,这个框架为处理这种情况提供了更好的选择?

EN

回答 1

Stack Overflow用户

发布于 2017-09-25 16:26:38

可以在每次投票之前或之后使用智能轮询器重新配置MessageSource

编辑

代码语言:javascript
复制
@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/>中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46409658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档