在Camel中调用运行时延迟



我是Camel的新手,我正在尝试通过为路由设置新的延迟来实现更改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);
    }
}

My 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>

请帮助。

谢谢。

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>

最新更新