While loop 骆驼有一个圈吗?

While loop 骆驼有一个圈吗?,while-loop,apache-camel,esb,do-while,While Loop,Apache Camel,Esb,Do While,有没有一个想法,而循环骆驼? 我们使用Camel进行批处理(我知道这不是ESB的职责)。在ESB中处理消息时,我希望不断检查其他内容的状态。我只能找到一个循环定义次数的循环,即用于测试的循环,或每x秒检查一次的石英计时器。这两个都不太合适 有什么建议吗,或者我只是要求ESB之外的东西吗?这样做怎么样: <camelContext id="myContext"> <route id ="initializer"> <!--This will b

有没有一个想法,而循环骆驼? 我们使用Camel进行批处理(我知道这不是ESB的职责)。在ESB中处理消息时,我希望不断检查其他内容的状态。我只能找到一个循环定义次数的循环,即用于测试的循环,或每x秒检查一次的石英计时器。这两个都不太合适


有什么建议吗,或者我只是要求ESB之外的东西吗?

这样做怎么样:

<camelContext id="myContext">
    <route id ="initializer">
        <!--This will be created only once -->
        <from uri="timer://foo?repeatCount=1"/>
        <to uri="seda:mySedaQueue"/>
    </route>

    <route id ="myRoute">
        <from uri="seda:mySedaQueue"/>
        <choice>
            <when>
                <simple>{your condition if you want to continue}</simple>
                ...
                <to uri="seda:mySedaQueue" />
            </when>
            <otherwise>
                ...
            </otherwise>
        </choice>
    </route>
</camelContext>

{如果要继续,请选择您的条件}
...
...

这样做怎么样:

<camelContext id="myContext">
    <route id ="initializer">
        <!--This will be created only once -->
        <from uri="timer://foo?repeatCount=1"/>
        <to uri="seda:mySedaQueue"/>
    </route>

    <route id ="myRoute">
        <from uri="seda:mySedaQueue"/>
        <choice>
            <when>
                <simple>{your condition if you want to continue}</simple>
                ...
                <to uri="seda:mySedaQueue" />
            </when>
            <otherwise>
                ...
            </otherwise>
        </choice>
    </route>
</camelContext>

{如果要继续,请选择您的条件}
...
...

骆驼计时器怎么样:

例如


参考资料:

骆驼计时器怎么样:

例如


参考资料:

尝试使用DynamicRouter

它使用一个表达式类来确定下一个发送交换的路由。如果表达式返回null,则表示它将停止路由

通过这种方式,您可以评估exchange内容并继续路由到同一路由,直到您决定停止,然后返回null

from("direct:start")
.dynamicRouter(new Expression() {
    @Override
    public <T> T evaluate(Exchange exchange, Class<T> type) {
        if (<your condition>) return (T) "direct:whileRoute";
        return null;
    }
})
.to("mock:finish");

from("direct:whileRoute")
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            // Do whatever you want
        }
    });
from(“直接:开始”)
.dynamicRouter(新表达式(){
@凌驾
公共T评估(交换,类类型){
if()返回(T)“direct:whileRoute”;
返回null;
}
})
。至(“模拟:完成”);
from(“直接:whileRoute”)
.进程(新处理器(){
@凌驾
公共作废进程(Exchange)引发异常{
//你想干什么就干什么
}
});

尝试使用DynamicRouter

它使用一个表达式类来确定下一个发送交换的路由。如果表达式返回null,则表示它将停止路由

通过这种方式,您可以评估exchange内容并继续路由到同一路由,直到您决定停止,然后返回null

from("direct:start")
.dynamicRouter(new Expression() {
    @Override
    public <T> T evaluate(Exchange exchange, Class<T> type) {
        if (<your condition>) return (T) "direct:whileRoute";
        return null;
    }
})
.to("mock:finish");

from("direct:whileRoute")
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            // Do whatever you want
        }
    });
from(“直接:开始”)
.dynamicRouter(新表达式(){
@凌驾
公共T评估(交换,类类型){
if()返回(T)“direct:whileRoute”;
返回null;
}
})
。至(“模拟:完成”);
from(“直接:whileRoute”)
.进程(新处理器(){
@凌驾
公共作废进程(Exchange)引发异常{
//你想干什么就干什么
}
});