Apache Camel Quartz2

问题描述 投票:0回答:1

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

<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调度程序的理解对于WINDOWS操作系统不正确,请更正我,因为我试图首先在我的Windows系统上执行它。

以下是apache camel执行的日志供参考:

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等。请指导如何实现同样的目标。

spring apache apache-camel scheduler quartz
1个回答
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();
}
© www.soinside.com 2019 - 2024. All rights reserved.