以编程方式将上下文范围的onCompletion()添加到Camel Context

时间:2013-06-12 19:48:51

标签: java apache-camel

有没有办法在Camel上下文中添加 onCompletion context-scoped'处理程序'? Camel onCompletion documentation显示了如何使用Spring XML DSL进行操作,但我无法找到以编程方式执行此操作的方法。

2 个答案:

答案 0 :(得分:1)

// define a global on completion that is invoked when the exchange is complete
onCompletion().to("log:global").to("mock:sync");

答案 1 :(得分:0)

由于onComplete只能是RouteBuilder范围。创建真正的全局onComplete处理器

// Initialize an instance of the definition
OnCompletionDefinition globalOnComplete = new OnCompletionDefinition();
globalOnComplete.to("log:onComplete");

在您的RouteBuilder实现中,在定义任何路由之前,将上面的实例添加到定义中

@Override
public void configure() throws Exception {
    // Add onCompletion instance for all routes within this RouteBuilder
    this.getRouteCollection()
            .getOnCompletions()
             .add(globalOnComplete);


    // Route definition
    from("direct:input").to("log:output");        
}