情况如下。
我正在尝试将请求发送到错误的IP,并想捕获请求超时异常。
虽然我向错误的IP发送了请求,但还是正常结束了。
来源如下。
try {
FluentProducerTemplate fluentProducerTemplate = exchange.getContext().createFluentProducerTemplate();
log.debug("START");
// 111.111.111.111:1111 is wrong IP sample
Message message = fluentProducerTemplate.to("netty-http:http://111.111.111.111:1111/?clientMode=true&connectTimeout=5000").request(Message.class);
log.debug("DONE");
} catch ( Exception e ) {
log.debug("FAIL");
}
我认为应该以“FAIL”结束,但事实并非如此。从“START”开始 5 秒后打印日志消息“DONE”。并且回复消息为空。
连接超时有什么办法可以例外吗?
我尝试了一切方法来解决这个问题,但最终还是失败了。您可以使用ProducerTemplate代替FluentProducerTemplate来解决问题。