从 Apache Camel 中的当前路由返回并继续路由 [英] return back from current route in Apache Camel and continue routing

查看:28
本文介绍了从 Apache Camel 中的当前路由返回并继续路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有 2 条路线 AB.A 路线在某些点称为路线 B.我希望在 B 路线中的某些条件下返回 A 并继续 A 路线,因此 stop() 不适合我的情况.我想保持我的路线不变,而无需进行认真的重构

Say we have 2 routes A and B. A route at some point calls route B. I'd like on certain condition in B route return back to A and continue A routing only, so stop() is unsuitable in my case. I'd like to keep my routes as is without serious refactoring

推荐答案

您可以使用窃听来实现.在这种情况下,您的逻辑必须更改:

You can implement this using wiretap. In that case your logic must be changed:

  • Route B 拆分为 B-common 和 B-cont,其中 B-cont 包含必须在将​​结果返回给 A 后处理的逻辑
  • 逻辑必须从在特定条件下返回A并继续处理B"更改为在反转特定条件下窃听到B-cont"

有关窃听的详细信息在这里:http://camel.apache.org/wire-tap.html

Details about wiretap are here: http://camel.apache.org/wire-tap.html

配置示例:

<route>
    <from uri="direct:A"/>
    <log message="B is starting"/>
    <to uri="direct:B"/>
    <log message="B is finished"/>
</route>
<route>
    <from uri="direct:B"/>
    <!-- Common B logic here -->
    <log message="Common B logic finished"/>
    <choice>
        <when>
            <!-- your condition inverted -->
            <wireTap uri="direct:B-cont"/>
        </when>
    </choice>
    <!-- Remaining B logic if needed to prepare required response for A -->
    <log message="Response to A prepared"/>
</route>
<route>
    <from uri="direct:B-cont"/>
    <log message="B processing after returning response to A"/>
    <!-- remaining B logic -->
</route>

此类路由的日志输出将如下所示:

Log output for such routes will looks like:

B is starting
Common B logic finished
Response to A prepared
B is finished
B processing after returning response to A

或:

B is starting
Common B logic finished
Response to A prepared
B processing after returning response to A
B is finished

或:

B is starting
Common B logic finished
B processing after returning response to A
Response to A prepared
B is finished

如您所见,有线窃听"路由将与调用它的路由的其余部分并行运行(在大多数情况下).详细信息可以在窃听文档 http://camel.apache.org/wire-tap 中找到.html

As you can see "wire-tapped" route will run in parallel (for most cases) to the rest of the route from where it was called. Details can be found in wire-tap documentation http://camel.apache.org/wire-tap.html

这篇关于从 Apache Camel 中的当前路由返回并继续路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆