在Camel中调用运行时延迟

时间:2014-03-26 21:33:55

标签: java apache-camel delay

我是Camel的新手,我正在尝试通过为Route设置新的延迟来实现更改Camel默认延迟的功能。我正在停止路线并启动它,但它似乎考虑默认延迟而不是考虑新的延迟。我的SpringCamelTester.java代码如下:

public class SpringCamelTester {

    private ApplicationContext context = null;

    public static void main(String[] args) throws Exception {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("Context.xml");
        CamelContext cc = (CamelContext) context.getBean("testingDelay");

        RouteContext cc2 = cc.getRoute("s2d").getRouteContext();

        cc2.setDelayer((long) 5000);
        cc.stopRoute("s2d");
        cc.startRoute("s2d");

        Thread.sleep(50000);
    }
}

我的Context.xml如下:

<camelContext id="testingDelay" xmlns="http://camel.apache.org/schema/spring">
    <route id="s2d">
        <from uri="file:D:/Workshop/Rough/CamelTest/CamelSink/Source?noop=true" />

        <!-- <log message="Output of message from Queue: ${in.body}"/> -->
        <bean ref="fileProcessor" method="propcess"/>

        <to uri="file:D:/Workshop/Rough/CamelTest/CamelSink/Destination" />
    </route>
</camelContext>

请帮忙。

谢谢。

1 个答案:

答案 0 :(得分:0)

Camel仅支持在加载路径时设置延迟时间。 你可以像这样设置路线上的延迟值

<camelContext id="testingDelay" xmlns="http://camel.apache.org/schema/spring">
    <route id="s2d" delayer="20000">
        <from uri="file:D:/Workshop/Rough/CamelTest/CamelSink/Source?noop=true" />

        <!-- <log message="Output of message from Queue: ${in.body}"/> -->
        <bean ref="fileProcessor" method="propcess"/>

        <to uri="file:D:/Workshop/Rough/CamelTest/CamelSink/Destination" />
    </route>
</camelContext>