【问题标题】:stop route in otherwise否则停止路线
【发布时间】:2011-10-13 09:49:57
【问题描述】:

你有这样的路线

<route id="route1">
<from uri="activemq:queuer1"/>
    <choice>
        <when>
            <simple>${header.urn} regex '^user*'</simple>
            <to uri="xslt:classpath:/xslt/rdf/user.xsl"/>
        </when>
        <when>
            <simple>${header.urn} regex '^userdata:.*'</simple>
            <to uri="xslt:classpath:/xslt/rdf/userdata.xsl"/>
        </when>
        ....
        <otherwise>
            <setHeader headerName="errorMsg ">
                <constant>no xsl file for this type</constant>
            </setHeader>
            <to uri="activemq:error"/>
        </otherwise> 
    </choice>
    <process ref="importer"/>
</route>

现在,如果路由进入 else 部分,则不应处理该消息。 如果消息进入,我可以以某种方式停止路由吗?

我可能会在所有 when 部分中添加流程部分并在最后删除它。 但我们已经有几个部分,还有更多即将推出。

其他解决方案将是首选。

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    您可以添加&lt;stop/&gt; 以停止继续路由消息。

    在 Java 代码中:

    exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
    

    在 Java DSL 中:

    .when(simple("${in.header.CamelHttpResponseCode} == 404"))
        .stop()
    .otherwise()
        ...
    

    【讨论】:

    • 这是一个非常有用的技术。是否可以将此文档添加到 Camel 网站?它可能已经在那里,但我找不到。
    • 我在文档中也找不到这个,虽然克劳斯的书中有一个例子。
    • 此来源可能会有所帮助:Intercept
    • 从 3.14 (LTS) 开始的 Stop EIP 的文档
    猜你喜欢
    • 2017-05-31
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多