将 Camel 和 Netty 4 与无法访问的套接字一起使用不会 运行 进入 onException-part 但 returns 堆栈跟踪

Using Camel and Netty 4 with an unreachable Socket does not run into onException-part but returns the stacktrace

我有一个简单的 Camel 路由,其中​​ Netty 4 部分作为套接字的客户端。如果无法访问套接字,则会正确抛出 java.net.ConnectException 但不会在 onException 配置部分中捕获,而是作为 Exchange 正文传递。有没有机会抓住这个?

路线建设者

public void configure() throws Exception {
    if (faultProcessor != null) {
        onException(Exception.class).handled(true).process(faultProcessor).stop();
    }

    from(from)
        .routeId(routeId)
        .process(preProcessor)
        .loadBalance()
            .failover(attempts, false, true, java.io.IOException.class)
            .to("netty4:tcp://server:port?clientMode=true&sync=true&allowDefaultCodec=false&clientInitializerFactory=#clientInitializerFactory&disconnect=true&usingExecutorService=false&workerGroup=#sharedPool")
        .end()
        .process(postProcessor)
        .to(to);
}

堆栈跟踪

java.net.ConnectException: Cannot connect to server:port
at org.apache.camel.component.netty4.NettyProducer.openChannel(NettyProducer.java:419)
at org.apache.camel.component.netty4.NettyProducer$NettyProducerPoolableObjectFactory.makeObject(NettyProducer.java:487)
at org.apache.camel.component.netty4.NettyProducer$NettyProducerPoolableObjectFactory.makeObject(NettyProducer.java:482)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188)
at org.apache.camel.component.netty4.NettyProducer.process(NettyProducer.java:201)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:141)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)
at org.apache.camel.processor.loadbalancer.FailOverLoadBalancer.processExchange(FailOverLoadBalancer.java:277)
at org.apache.camel.processor.loadbalancer.FailOverLoadBalancer.process(FailOverLoadBalancer.java:232)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190)

您碰巧将负载均衡器步骤配置为不继承路由的错误处理程序。如果您使用

错误处理程序应该触发
.failover(java.io.IOException.class)

.failover(attempts, true, true, java.io.IOException.class)