Apache Camel Quartz2 - PullRequest
       29

Apache Camel Quartz2

0 голосов
/ 13 февраля 2019

Я пытаюсь реализовать планировщик с использованием 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>

Планировщик при исполнении выдает правильное время, т.е. он запланирован на следующую минуту согласно журналам, однако, как я ожидаюон ведет себя как cronjob в системе Linux, приложение завершает свою работу, не продолжая работать в качестве планировщика, и даже не выполняет многоадресные маршруты дальше.

Пожалуйста, исправьте меня, если я понимаю планировщик Quartzневерно для ОС WINDOWS, так как я пытаюсь выполнить его сначала в моей системе 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 голосов
/ 13 февраля 2019

Согласно предложению Клауса, я внес следующие изменения в свой основной метод, и теперь он работает, как и ожидалось.Ранее я использовал приведенный ниже код для инициализации моего контекста и запуска маршрутов, и поэтому 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();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...