2016-07-25 10 views
0

Ich ging durch diesen Post und implementiert EventListner. Best practice for handling low-level socket error in spring integration? Ich habe Frühling TCP implementiert Kanäle wie folgt:int-event: Inbound-Channel-Adapter funktioniert nicht, wenn es java.net.ConnectException: Connection refused: connect

<?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> 

-Service Activator

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

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

} 

Mein Service-Aktivator nicht genannt unten Ausnahme auf wird immer:

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] 

Ich da irgendetwas fehlt mir. Ich hoffe die event-type in int-event:inbound-channel-adapter ist eine passende. Bitte lassen Sie mich wissen, wenn ich etwas korrigieren muss.

+0

Warum würde ein Message-Handler aufgerufen, wenn es nicht einmal eine Verbindung gibt, geschweige denn eine Nachricht? Unklar, worüber du überrascht bist. – EJP

+0

Da es keine Verbindung gibt, eher eine Ausnahme, habe ich ein Spring-Ereignis für dieses Ausnahmeereignis definiert. Es sollte den Handler für dieses Ereignis aufrufen. –

Antwort

2

Verbindungsausnahmeereignisse werden nur generiert, nachdem eine Verbindung hergestellt wurde. Derzeit geben wir kein Ereignis für einen Fehler beim Erstellen einer Verbindung aus (z. B. Verbindung verweigert).

Die TcpConnectionExceptionEvent ist für eine Ausnahme auf eine bestehende TcpConnection.

Fühlen Sie sich frei, eine JIRA Improvement issue zu öffnen, und wir werden ein neues Ereignis hinzufügen.

+0

Okay wird es schaffen. –

+0

Ich habe eine erstellt, aber ich bin mir nicht sicher über Versionen in JIRA. https://jira.spring.io/browse/INT-4080 –