骆驼石英在卡拉夫没有像预期的那样工作

时间:2016-02-19 22:57:40

标签: apache-camel quartz-scheduler apache-karaf blueprint-osgi

我在karaf 4.0.3中遇到了apache camel quartz cron定时器的问题。看来,当石英作业执行时,它正在执行多次。以下示例蓝图作为我的" mass-orchestrator"的一部分加载。应用程序。 Hello World输出会立即打印多次。相反,它应该每2分钟打印一次。有谁知道这里发生了什么以及如何纠正它?

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
  xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0 
    http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd

    http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
    http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd

    http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.1.0
    http://aries.apache.org/schemas/blueprint-ext/blueprint-ext-1.1.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/blueprint"
    id="simple">
    <route>
        <from uri="quartz:myTimerName?cron=*+0/2+*+*+*+?" />
        <setBody>
            <simple>Hello World</simple>
        </setBody>
        <to uri="stream:out" />
    </route>
  </camelContext>
</blueprint>

然后我启动Karaf清洁并安装最新的骆驼(但我能够在许多版本的骆驼中重现,回到2.12)。

       __ __                  ____
   / //_/____ __________ _/ __/
  / ,<  / __ `/ ___/ __ `/ /_
 / /| |/ /_/ / /  / /_/ / __/
/_/ |_|\__,_/_/   \__,_/_/

Apache Karaf (4.0.3)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.

karaf@root()> feature:repo-add camel
Adding feature url mvn:org.apache.camel.karaf/apache-camel/LATEST/xml/features
karaf@root()> feature:install camel-blueprint
karaf@root()> feature:install camel-quartz
karaf@root()> feature:install camel-stream
karaf@root()> install mvn:com.cerner.cts.oss/mass-orchestrator/1.0.0-SNAPSHOT
Bundle ID: 66
karaf@root()> list
START LEVEL 100 , List Threshold: 50
ID | State     | Lvl | Version         | Name
----------------------------------------------------------------------------------
52 | Active    |  80 | 2.17.0.SNAPSHOT | camel-blueprint
53 | Active    |  80 | 2.17.0.SNAPSHOT | camel-catalog
54 | Active    |  80 | 2.17.0.SNAPSHOT | camel-commands-core
55 | Active    |  80 | 2.17.0.SNAPSHOT | camel-core
56 | Active    |  80 | 2.17.0.SNAPSHOT | camel-karaf-commands
57 | Active    |  80 | 2.2.6.1         | Apache ServiceMix :: Bundles :: jaxb-impl
58 | Active    |  80 | 3.1.4           | Stax2 API
59 | Active    |  80 | 4.4.1           | Woodstox XML-processor
60 | Active    |  80 | 2.17.0.SNAPSHOT | camel-quartz
61 | Active    |  80 | 1.4             | Commons DBCP
62 | Active    |  80 | 1.6.0           | Commons Pool
63 | Active    |  80 | 1.1.1           | geronimo-jta_1.1_spec
64 | Active    |  80 | 1.8.6.1         | Apache ServiceMix :: Bundles ::     quartz
65 | Active    |  80 | 2.17.0.SNAPSHOT | camel-stream
66 | Installed |  80 | 1.0.0.SNAPSHOT  | mass-orchestrator
karaf@root()> start 66
karaf@root()> Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
<snip>

karaf@root()>

1 个答案:

答案 0 :(得分:1)

cron应该是

0+0/2+*+*+*+?

每2分钟只运行一次。如果你使用*,则意味着它每隔一秒间隔运行一次。