gpt4 book ai didi

java - int-event :inbound-channel-adapter not working when there is java.net.ConnectException:连接被拒绝:连接

转载 作者:行者123 更新时间:2023-12-02 03:27:49 25 4
gpt4 key购买 nike

我浏览了这篇文章并实现了 eventListner。 Best practice for handling low-level socket error in spring integration?我已经实现了 Spring TCP channel ,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int-event="http://www.springframework.org/schema/integration/event"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration/event http://www.springframework.org/schema/integration/event/spring-integration-event.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<context:annotation-config />
<!--Deserializer for incoming data on the socket -->
<bean
class="org.springframework.integration.ip.tcp.serializer.ByteArraySingleTerminatorSerializer"
id="serializeAndDeserializer">
<constructor-arg type="byte" value="0" />
</bean>
<int:channel id="tcp-client-input" />

<int:channel id="message" />

<int:gateway id="gateway" service-interface="com.tcpclient.ClientGateway"
default-request-channel="tcp-client-input" default-reply-channel="message" />

<int-ip:tcp-connection-factory id="clientFactory"
type="client" host="10.255.233.21" port="1234" single-use="false"
so-timeout="10000" deserializer="serializeAndDeserializer" serializer="serializeAndDeserializer" />

<int-ip:tcp-outbound-channel-adapter
id="outBoundClient" channel="tcp-client-input" connection-factory="clientFactory"
retry-interval="60000" auto-startup="false" />

<int-ip:tcp-inbound-channel-adapter
id="inBoundClient" channel="message" connection-factory="clientFactory"
client-mode="true" auto-startup="false" retry-interval="60000" />
<int-event:inbound-channel-adapter
channel="eventChannel" error-channel="tcpReceiveError"
event- types="org.springframework.integration.ip.tcp.connection.TcpConnectionExceptionEvent"/>
<int:object-to-string-transformer
input-channel="message" output-channel="message-serviceActivator" />
<int:service-activator input-channel="message-serviceActivator"
method="onRtlsMessageArrival">
<bean class="com.tcpclient.HandleMessage" />
</int:service-activator>
</beans>
<小时/>

服务激活器

@ServiceActivator(inputChannel = "tcpReceiveError")
public void handleSocketFlags(Message m) {

System.out.println(m.getPayload());

}

以下异常未调用我的服务激活器:

java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.8.0_92]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_92]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_92]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_92]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_92]
at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_92]
at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_92]
at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_92]
at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_92]
at java.net.Socket.<init>(Unknown Source) ~[na:1.8.0_92]
at java.net.Socket.<init>(Unknown Source) ~[na:1.8.0_92]
at javax.net.DefaultSocketFactory.createSocket(Unknown Source) ~[na:1.8.0_92]
at org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory.createSocket(TcpNetClientConnectionFactory.java:76) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory.buildNewConnection(TcpNetClientConnectionFactory.java:49) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.obtainNewConnection(AbstractClientConnectionFactory.java:114) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.obtainConnection(AbstractClientConnectionFactory.java:77) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.getConnection(AbstractClientConnectionFactory.java:67) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.getConnection(AbstractClientConnectionFactory.java:31) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.integration.ip.tcp.connection.ClientModeConnectionManager.run(ClientModeConnectionManager.java:54) ~[spring-integration-ip-4.2.5.RELEASE.jar:na]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.8.0_92]
at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [na:1.8.0_92]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [na:1.8.0_92]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [na:1.8.0_92]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_92]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_92]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_92]

我缺少任何东西。我希望 int-event:inbound-channel-adapter 中的 event-type 是合适的。如果我需要更正某些内容,请告诉我。

最佳答案

连接异常事件仅在建立连接后生成,目前我们不会针对创建连接失败(例如连接被拒绝)发出事件。

TcpConnectionExceptionEvent 用于现有 TcpConnection 上的异常。

欢迎打开JIRA Improvement issue我们将考虑添加一个新事件。

关于java - int-event :inbound-channel-adapter not working when there is java.net.ConnectException:连接被拒绝:连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38566363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com