阿帕奇骆驼Quartz2

时间:2019-02-13 09:15:51

标签: spring apache apache-camel scheduler quartz

我正在尝试使用Apache Camel Quartz2实现调度程序,该调度程序每分钟执行一次路由并按预期执行一些任务。 我正在使用Spring DSL来实现与Apache骆驼相关的路由,如下所示:

<camelContext
        xmlns="http://camel.apache.org/schema/spring">
        <propertyPlaceholder id="properties"
            location="classpath:application.properties" />
        <route>
            <from uri="quartz2://spring?cron=0+*+*+?+*+*" />
            <multicast parallelProcessing="true">
                <to uri="direct:DomainsWithFTPUsers" />
                <to uri="direct:DomainsWithoutFTPUsers" />
            </multicast>

计划程序在执行时会给出正确的时间,即按日志计划在下一分钟进行,但是正如我期望的那样,它在Linux系统上的行为就像cronjob一样,该应用程序退出时并未继续作为计划程序工作,甚至根本不执行多播路由。

如果我对Quartz Scheduler的理解对于WINDOWS OS不正确,请纠正我,因为我想先在Windows系统上执行它。

以下是Apache骆驼执行的日志,以供参考:

14:33:50.725 [main] INFO  org.springframework.context.support.ClassPathXmlApplicationContext  - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7a46a697: startup date [Wed Feb 13 14:33:50 IST 2019]; root of context hierarchy
14:33:50.788 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [applicationContext.xml]
14:33:52.523 [main] INFO  org.springframework.jdbc.datasource.DriverManagerDataSource  - Loaded JDBC driver: org.h2.Driver
14:33:52.842 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) is starting
14:33:52.842 [main] INFO  org.apache.camel.management.ManagedManagementStrategy  - JMX is enabled
14:33:52.998 [main] INFO  org.apache.camel.impl.converter.DefaultTypeConverter  - Loaded 183 type converters
14:33:53.076 [main] INFO  org.apache.camel.component.quartz2.QuartzComponent  - Create and initializing scheduler.
14:33:53.076 [main] INFO  org.apache.camel.component.quartz2.QuartzComponent  - Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX.
14:33:53.108 [main] INFO  org.quartz.impl.StdSchedulerFactory  - Using default implementation for ThreadExecutor
14:33:53.123 [main] INFO  org.quartz.simpl.SimpleThreadPool  - Job execution threads will use class loader of thread: main
14:33:53.139 [main] INFO  org.quartz.core.SchedulerSignalerImpl  - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
14:33:53.139 [main] INFO  org.quartz.core.QuartzScheduler  - Quartz Scheduler v.2.2.1 created.
14:33:53.139 [main] INFO  org.quartz.simpl.RAMJobStore  - RAMJobStore initialized.
14:33:53.139 [main] INFO  org.quartz.core.QuartzScheduler  - Scheduler meta-data: Quartz Scheduler (v2.2.1) 'DefaultQuartzScheduler-camel-1' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

14:33:53.139 [main] INFO  org.quartz.impl.StdSchedulerFactory  - Quartz scheduler 'DefaultQuartzScheduler-camel-1' initialized from an externally provided properties instance.
14:33:53.139 [main] INFO  org.quartz.impl.StdSchedulerFactory  - Quartz scheduler version: 2.2.1
14:33:53.186 [main] INFO  org.apache.camel.component.quartz2.QuartzEndpoint  - Job Camel_camel-1.spring (triggerType=CronTriggerImpl, jobClass=CamelJob) is scheduled. Next fire date is Wed Feb 13 14:34:00 IST 2019
14:33:53.405 [main] INFO  org.apache.camel.spring.SpringCamelContext  - AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
14:33:53.405 [main] INFO  org.apache.camel.spring.SpringCamelContext  - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
14:33:53.521 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Route: route1 started and consuming from: Endpoint[quartz2://spring?cron=0+*+*+%3F+*+*]
14:33:53.524 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Route: route2 started and consuming from: Endpoint[direct://DomainsWithFTPUsers]
14:33:53.528 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Route: route3 started and consuming from: Endpoint[direct://DomainsWithoutFTPUsers]
14:33:53.532 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Route: route4 started and consuming from: Endpoint[direct://scpToDBServer]
14:33:53.533 [main] INFO  org.apache.camel.component.quartz2.QuartzComponent  - Starting scheduler.
14:33:53.533 [main] INFO  org.quartz.core.QuartzScheduler  - Scheduler DefaultQuartzScheduler-camel-1_$_NON_CLUSTERED started.
14:33:53.533 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Total 4 routes, of which 4 is started.
14:33:53.535 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) started in 0.691 seconds
14:33:53.535 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) is starting
14:33:53.535 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Total 4 routes, of which 4 is started.
14:33:53.535 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) started in 0.000 seconds
14:33:56.538 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) is shutting down
14:33:56.540 [main] INFO  org.apache.camel.impl.DefaultShutdownStrategy  - Starting to graceful shutdown 4 routes (timeout 300 seconds)
14:33:56.540 [Camel (camel-1) thread #0 - ShutdownTask] INFO  org.apache.camel.component.quartz2.QuartzEndpoint  - Pausing trigger Camel_camel-1.spring
14:33:56.556 [Camel (camel-1) thread #0 - ShutdownTask] INFO  org.apache.camel.impl.DefaultShutdownStrategy  - Route: route4 shutdown complete, was consuming from: Endpoint[direct://scpToDBServer]
14:33:56.556 [Camel (camel-1) thread #0 - ShutdownTask] INFO  org.apache.camel.impl.DefaultShutdownStrategy  - Route: route3 shutdown complete, was consuming from: Endpoint[direct://DomainsWithoutFTPUsers]
14:33:56.556 [Camel (camel-1) thread #0 - ShutdownTask] INFO  org.apache.camel.impl.DefaultShutdownStrategy  - Route: route2 shutdown complete, was consuming from: Endpoint[direct://DomainsWithFTPUsers]
14:33:56.556 [Camel (camel-1) thread #0 - ShutdownTask] INFO  org.apache.camel.impl.DefaultShutdownStrategy  - Route: route1 shutdown complete, was consuming from: Endpoint[quartz2://spring?cron=0+*+*+%3F+*+*]
14:33:56.556 [main] INFO  org.apache.camel.impl.DefaultShutdownStrategy  - Graceful shutdown of 4 routes completed in 0 seconds
14:33:56.571 [main] INFO  org.apache.camel.component.quartz2.QuartzEndpoint  - Deleting job Camel_camel-1.spring
14:33:56.571 [main] INFO  org.apache.camel.component.quartz2.QuartzComponent  - Shutting down scheduler. (will wait for all jobs to complete first.)
14:33:56.571 [main] INFO  org.quartz.core.QuartzScheduler  - Scheduler DefaultQuartzScheduler-camel-1_$_NON_CLUSTERED shutting down.
14:33:56.571 [main] INFO  org.quartz.core.QuartzScheduler  - Scheduler DefaultQuartzScheduler-camel-1_$_NON_CLUSTERED paused.
14:33:56.681 [main] INFO  org.quartz.core.QuartzScheduler  - Scheduler unregistered from name 'quartz:type=QuartzScheduler,name=DefaultQuartzScheduler-camel-1,instance=NON_CLUSTERED' in the local MBeanServer.
14:33:56.681 [main] INFO  org.quartz.core.QuartzScheduler  - Scheduler DefaultQuartzScheduler-camel-1_$_NON_CLUSTERED shutdown complete.
14:33:56.681 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) uptime 3.146 seconds
14:33:56.681 [main] INFO  org.apache.camel.spring.SpringCamelContext  - Apache Camel 2.15.1 (CamelContext: camel-1) is shutdown in 0.143 seconds

根据日志,它不会进一步记录为路由记录的消息,即direct:DomainsWithFTPUsers等。 请指导如何实现相同的目标。

1 个答案:

答案 0 :(得分:1)

根据Claus的建议,我对我的主要方法进行了以下更改,并且现在可以按预期运行。 以前,我使用下面的代码初始化上下文并启动路由,因此JVM停止了它的执行:

public static void main(String[] args) throws Exception {
        ApplicationContext appContext = new ClassPathXmlApplicationContext(
                "applicationContext.xml");
        CamelContext camelContext = SpringCamelContext.springCamelContext(
                appContext, false);
    }

使JVM运行的正确方法:

public static void main(String[] args) throws Exception {
    Main main = new Main();
    main.enableHangupSupport();
    main.setFileApplicationContextUri("classpath:applicationContext.xml");
    main.run();
}