否则停止路线

mjs*_*ier 7 apache-camel

嗨有这样的路线

<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>
Run Code Online (Sandbox Code Playgroud)

现在,如果路由进入其他部分,则不应处理该消息.如果消息进入其他情况,我可以以某种方式停止路线吗?

可能性是我在所有部件中添加过程部件并在最后删除它.但是我们已经有几个部件和更多部件.

其他解决方案将是首选.

Cla*_*sen 22

您可以添加一个<stop/>以停止继续路由邮件.

在Java代码中:

exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
Run Code Online (Sandbox Code Playgroud)

在Java DSL中:

.when(simple("${in.header.CamelHttpResponseCode} == 404"))
    .stop()
.otherwise()
    ...
Run Code Online (Sandbox Code Playgroud)

  • 这是一项非常有用的技术.是否可以将此文档添加到Camel网站?它可能已经存在但我找不到它. (4认同)