我有一个在运行时管理的RouteBuilder。我想在没有向客户端发送响应的情况下抛出错误时将客户端从路由中断开。我还需要在整个过程中保持路由。如何在不停止路线的情况下断开客户端连接?任何帮助将不胜感激。
@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)
我通过在交换变量的响应主体上设置null来解决我的问题,因此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)));
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());
}