将Camel和Netty 4与无法访问的Socket一起使用不会遇到onException-part但会返回stacktrace

时间:2016-01-26 08:39:22

标签: java apache-camel netty

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

  • Camel 2.16.1
  • Netty 4.0.33.Final

Routebuilder

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)

1 个答案:

答案 0 :(得分:1)

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

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

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