我浏览了下面的帖子:在spring集成中,如何捕捉不同的异常?
在此之后,我为org.springframework.integration.ip.tcp.connection.TcpConnectionExceptionEvent
定义了事件处理程序如下所示:
<int:gateway id="gateway" service-interface="com.tcpclient.ClientGateway"
default-request-channel="tcp-client-input"
default-reply-channel="message"/>
<int-ip:tcp-outbound-channel-adapter
id="outBoundClient" channel="tcp-client-input"
retry-interval="60000" auto-startup="true"/>
<int-ip:tcp-inbound-channel-adapter
id="inBoundClient" channel="message" auto-startup="false"
retry-interval="60000"/>
<int-ip:tcp-connection-event-inbound-channel-adapter
channel="tcpReceiveError"
event-types="org.springframework.integration.ip.tcp.connection.TcpConnectionExceptionEvent"/>
我的服务激活程序是:
@Component
public class ErrorHandler{
private static final Logger logger = LoggerFactory.getLogger(ErrorHandler.class);
@ServiceActivator(inputChannel = "tcpReceiveError")
public void handleError(Message m) {
logger.error("TcpError", m.getPayload());
}
}
首先,如果我第一次尝试连接时主机没有启动或端口没有打开,我的handleError(Message m)
不会按照下面的对话执行。
int事件:存在java.net.ConnectException时入站通道适配器不工作:连接被拒绝:连接
但是,一旦连接并且我开始接收消息,如果服务器关闭端口或在两者之间发生故障,则不会执行handleError(Message m)
。
如果我有一些错误的配置,请告诉我。
我想这是基于这个问题。
在这种情况下,这是因为您的连接工厂不是弹簧管理的,所以它没有事件发布者。
您应该让创建连接工厂的bean实现ApplicationEventPublisherAware
,并在字段中保存发布者。然后,在创建连接工厂时,需要设置属性。
如果没有这些,您应该会在日志中看到这样的警告。。。
this.logger.warn("No publisher available to publish " + event);