代码之家  ›  专栏  ›  技术社区  ›  Hassam Abdelillah

基于定时器和直接路由构造骆驼路由

  •  0
  • Hassam Abdelillah  · 技术社区  · 5 年前

    我想用camel实现一条路线,分别满足两个要求:

    • 使用石英开始一天中的特定时间(凌晨3点)的路线
    • 从其他路线消费(直接:myOtherRoute)

    我已经有了一条直接消费的路线:myOtherRoute,我现在想要实现的是添加开始计时器。

    from("direct:myOtherRoute")
                .marshal()
                .zipFile()
                .setHeader(Exchange.FILE_NAME, constant(endpointsURLs.get(EXTRACT_ZIP_FILENAME)))
                .log("Generate ZIP")
                .to("file:" + endpointsURLs.get(EXTRACT_ZIP_DIR) + "?doneFileName=" + endpointsURLs.get(EXTRACT_ZIP_TRIGGER));
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Mahdi Karami    5 年前

    处理此问题的一个糟糕方法是,可以在camel生成器中运行TimerTask并添加routedefinitions或挂起路由。如果你的问题没有解决,告诉我表明我的目的。

        2
  •  0
  •   aldebaran-ms    5 年前

    请看一下:

    Apache Camel : Quartz2

    package com.test.camel.quartz2;
    
    import org.apache.camel.spring.SpringRouteBuilder;
    import org.springframework.stereotype.Component;
    
    @Component
    public class QuartzTest extends SpringRouteBuilder {
    
        @Override
        public void configure() throws Exception {
    
            from("quartz2://myGroup/myTimerName?cron=0+0+3+?+*+*+*").to("direct:myOtherRoute");
    
            from("direct:myOtherRoute").log("Running");
        }
    
    }
    

    我添加了可以与spring boot一起使用的完整测试类。记住要导入maven依赖项!

    奖励:要创建cron模式,可以使用以下网站 cron-expression-generator-quartz 记住用“+”符号替换空格,如camel quartz2页所述


    注意:如果需要quartz 1.x兼容性,请使用以下选项: Apache Camel : Quartz