从Apache Camel中的当前路由返回并继续路由 [英] return back from current route in Apache Camel and continue routing
问题描述
说我们有两条路线 A 和 B . 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:
- 路线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屋!