代码之家  ›  专栏  ›  技术社区  ›  Makky

SpringIntegration Cron触发器

  •  1
  • Makky  · 技术社区  · 6 年前

    嗨,我正在使用SpringIntegration和触发器来轮询目录。到目前为止一切都很好。

    但我在民意测验开始和结束时间都有问题,大概是下午12:05和18:15

    0 0/1 12-18 ? * MON-FRI
    

    上面的方法在12到18之间每分钟都很有效,但我也找不到方法来设定时间

    支持吗

    @Bean
        public IntegrationFlow inboundFileIntegration(
    
        ) {
            CronTrigger cronTrigger = new CronTrigger("0 0/1 12-18 ? * MON-FRI");
    
    
            return IntegrationFlows.from(fileReadingMessageSource(),
                    c -> c.poller(Pollers.trigger(cronTrigger)
                            .maxMessagesPerPoll(10).advice(new AbstractMessageSourceAdvice() {
                                @Override
                                public Message<?> afterReceive(Message<?> message, MessageSource<?> messageSource) {
                                    System.out.println("after");
                                    return message;
                                }
    
                                @Override
                                public boolean beforeReceive(MessageSource<?> source) {
                                    System.out.println("before");
                                    return true;
                                }
                            })))
    //                        .transactionSynchronizationFactory(transactionSynchronizationFactory())
    //                        .transactional(transactionManager())))
                    .log()
                    .transform(Files.toStringTransformer())
                    .transform(o -> {
    //                    jmsTemplate.convertAndSend("testing_queue", o);
                        System.out.println(o);
                        return o;
                    })
    
    
                    .channel(ApplicationConfiguration.INBOUND_CHANNEL)
                    .get();
        }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   syntagma    6 年前

    你可以按照设定时间的方式设定分钟:

    0 15-35 12-17 1/1 * ? MON-FRI