当前位置: 首页 > 知识库问答 >
问题:

阿帕奇骆驼Quartz2

曹茂材
2023-03-14

我试图使用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>
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个答案

皇甫雨华
2023-03-14

根据克劳斯的建议,我对我的主要方法做了以下修改,现在它正像预期的那样工作。之前,我使用下面的代码初始化上下文并启动路由,因此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();
}
 类似资料:
  • 遵循官方文件(https://camel.apache.org/manual/component-dsl.html#_using_component_dsl)我创建了以下代码: 但是中的告诉我: 并且中的特性不建议导入相应的库。 有人能给我指出正确的方向吗? 我必须理解的概念才能做到这一点吗?

  • 考虑到apache Camel,我有一个问题:是否可以通过代码来创建全局拦截器,例如AOP?拦截器应该跳过endpoint还是模仿endpoint? 提前致谢

  • 我们需要的是直接的API来设置和使用集群消息队列。我们最初的计划是使用Camel在集群JMS或ActiveMQ队列上进行消费/生产。Kafka如何使这项任务变得更容易?在任何一种情况下,应用程序本身都将在WebLogic服务器上运行。 消息传递将是点对点类型,其中有多个相同服务的实例在运行,但根据负载平衡策略,只有一个实例应该处理消息并发出结果。消息队列也是群集的,因此服务实例或队列实例的失败都不

  • 我对骆驼生产商有很好的了解,但我不能对各种骆驼消费者保持清醒的头脑。特别是事件驱动消费者和轮询消费者,camel如何知道为这些消费者调用回调? 消费者的一般流量是多少?

  • 我在projet中使用ApacheCamel,我想使用Product注释发送文件中的对象。首先,可能吗?有更好的办法吗? 其次,我尝试了这个代码片段: 当我调用发布方法时,生产者不是注入(null)。有人有主意吗?提前谢谢。

  • 我在Spring Boot和camel-config.xml文件中使用Apache Camel。我创建了一个每秒运行一次的简单路由,并运行一个类方法: 我读了很多试图解决这个问题的书。我听到的是吼声: 发生的事情叫做“失火” 有一个参数允许配置失火说明 根据Apache Camel文档,如果使用的是cron表达式,则不能使用trigger.xxx选项(该选项允许配置失火指令)。 根据Apache