【问题标题】:Apache Camel: Call route again or dynamic routesApache Camel:再次调用路由或动态路由
【发布时间】:2014-11-25 02:08:56
【问题描述】:

我正在使用 JBoss Fuse 6.1.0Camel 2.10.0.redhat-60024。 路线列表是已知的。例如:#start, #step1, #step2, #step3, #finish

但我不知道顺序。或者有时可能不需要某些路线。我只会在#router 路线上知道(请参阅下面的代码)。

例如:#start, #step2, #step1, #step3, #finish.#start, #step1, #step3, #finish. 等。

但是Camel 2.10.0没有dynamicRouter这样的东西。我决定做这样的事情:

<?xml version="1.0" encoding="UTF-8"?>
...
<camelContext id="blueprintContext" trace="true"
    xmlns="http://camel.apache.org/schema/blueprint">
    <route id="start">
        <from uri="..." />
        <to uri="vm:router" />
    </route>
    <route id="router">
        <from uri="vm:router" />
        <bean ref="stepGenerator" method="nextStep" />
        <choice>
            <when>
                <simple>${header.step} contains 'step1'</simple>
                <to uri="vm:step1" />
            </when>
            <when>
                <simple>${header.step} contains 'step2'</simple>
                <to uri="vm:step2" />
            </when>
            <when>
                <simple>${header.step} contains 'step3'</simple>
                <to uri="vm:step3" />
            </when>
            <when>
                <simple>${header.step} contains 'finish'</simple>
                <to uri="vm:finish" />
            </when>
        </choice>
    </route>
    <route id="step1">
        <from uri="vm:step1" />
        <log message="Step 1 started." />
        <!-- Some logic -->
        <to uri="vm:router" />
    </route>
    <route id="step2">
        <from uri="vm:step2" />
        <log message="Step 2 started." />
        <!-- Some logic -->
        <to uri="vm:router" />
    </route>
    <route id="step3">
        <from uri="vm:step3" />
        <log message="Step 3 started." />
        <!-- Some logic -->
        <to uri="vm:router" />
    </route>
    <route id="finish">
        <from uri="vm:finish" />
        <log message="Finished!" />
    </route>
</camelContext>

假设我们有下一个序列:#start, #step1, #step2, #step3, #finish。如果您尝试运行,它将在#start -&gt; #router-&gt; #step1 停止。

#step1 &lt;to uri="vm:router" /&gt; 中不起作用。如果你调用 route 两次,它将不起作用。为什么? 在 Camel 2.10.0 中如何解决这种情况?

【问题讨论】:

    标签: jms apache-camel jboss6.x


    【解决方案1】:

    根据the camel website 介绍了动态路由器模式 2.5 版。我相信这对你有用...

    【讨论】:

    • 哦。我在蓝图中有一个旧的 XSD 架构,它告诉我不存在“动态路由”标签。感谢您的警惕!
    猜你喜欢
    • 2018-07-01
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多