2016-12-16 106 views
-1

我有一个在运行时管理的RouteBuilder。我想在发送错误而不向客户端发送响应时断开我的客户端与路由的连接。我也需要在整个过程中保持路由。我可以做什么来断开客户端而不停止我的路线?任何帮助将不胜感激。如果发生错误并继续路由,Apache Camel从路由断开连接

@Override 
public void configure() throws Exception { 

    onException(Exception.class) 
    .handled(true) 
    .process(new Processor() { 

     @Override 
     public void process(Exchange exchange) throws Exception { 
      Log.error(String.format(Constants.ERROR_ROUTING_TO, endPointFrom.toUrl(), endPointTo.toUrl(), 
       exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class))); 
      //TODO I WANT TO DISCONNECT FROM ROUTE HERE 
     } 

    }); 

    from(endPointFrom.toUrl()) 
    .routeId(endPointFrom.getId()) 
    .description(endPointFrom.toString()) 
    .process(new Processor() { 

     @Override 
     public void process(Exchange exchange) throws Exception { 


     } 
    }) 
    .to(endPointTo.toUrl()); 

} 
+0

取决于您正在使用的组件/客户端,以及这是否可能。你不会说什么正在使用。 –

+0

我忘了这个,我使用码头组件 –

回答

0

我通过交换变量设置为null的响应体等Apache的骆驼断开连接客户端不发送响应消息解决我的问题。

@Override 
public void configure() throws Exception { 

    onException(Exception.class) 
    .handled(true) 
    .process(new Processor() { 

     @Override 
     public void process(Exchange exchange) throws Exception { 
      Log.error(String.format(Constants.ERROR_ROUTING_TO, endPointFrom.toUrl(), endPointTo.toUrl(), 
       exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class))); 
       exchange.getOut().setBody(null); 
     } 

    }); 

    from(endPointFrom.toUrl()) 
    .routeId(endPointFrom.getId()) 
    .description(endPointFrom.toString()) 
    .process(new Processor() { 

     @Override 
     public void process(Exchange exchange) throws Exception { 

     } 

    }) 
    .to(endPointTo.toUrl()); 

}