2016-03-15 85 views
0

我使用Spring集成來處理服務器和客戶端之間的自定義TCP協議。這是我的context.xml:Spring集成不響應

<int-ip:tcp-connection-factory id="serverConnectionFactory" 
           type="server" 
           host="" 
           port="5678" 
           so-linger="5000" 
           so-keep-alive="true" 
           single-use="false" 
           using-nio="true" 
           so-timeout="5000" 
           serializer="customeMessageSerializerDeserializer" 
           deserializer="customeMessageSerializerDeserializer"/> 

<int-ip:tcp-inbound-channel-adapter id="inAdapter.server" 
            channel="toSA" 
            connection-factory="serverConnectionFactory"/> 

<int:channel id="toSA" datatype="com.my.Message"/> 

<int:service-activator input-channel="toSA" 
         output-channel="toObAdapter" 
         ref="handleMessage" 
         method="handle"/> 

<int:channel id="toObAdapter"/> 

<int-ip:tcp-outbound-channel-adapter id="outAdapter.server" 
            channel="toObAdapter" 
            connection-factory="serverConnectionFactory"/> 

<bean id="handleMessage" class="com.my.MessageHandler"/> 
<bean id="customeMessageSerializerDeserializer" 
     class="com.my.MessageSerializyerDeserializer"/> 

當我通過tomcat的它爲藪幾分鐘內部署,並把它轉化爲對客戶端沒有反應。發現一個錯誤:

org.springframework.messaging.MessageHandlingException: Unable to find outbound socket 
at  org.springframework.integration.ip.tcp.TcpSendingMessageHandler.handleMessageInternal( TcpSendingMessageHandler.java:122) 
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) 
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) 
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147) 
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120) 
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) 
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442) 
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392) 
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) 
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) 
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) 
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput( AbstractMessageProducingHandler.java:231) 
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput( AbstractMessageProducingHandler.java:154) 
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs( AbstractMessageProducingHandler.java:102) 
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal( AbstractReplyProducingMessageHandler.java:105) 
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) 
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) 
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:147) 
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:120) 
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) 
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442) 
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392) 
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) 
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) 
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) 
at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:105) 
at org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter.onMessage(TcpReceivingChannelAdapter.java:87) 
at org.springframework.integration.ip.tcp.connection.TcpNioConnection.sendToChannel(TcpNioConnection.java:370) 
at org.springframework.integration.ip.tcp.connection.TcpNioConnection.run(TcpNioConnection.java:239) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 

我想知道如何解決它,以及它錯在哪裏。

回答

0

使用collaborating channel adapters時,必須確保在出站消息中設置ip_connectionId標頭,以便適配器知道將其寫入哪個套接字。

通常,通過這樣的簡單流程,框架將負責將來自入站消息的頭部傳播到出站消息。

所以我需要看到這種方法,看看你在做什麼。

你的'handleMessage`代碼是什麼樣的?

另一種可能性是5秒超時 - 如果您的服務需要的時間超過連接將不再存在的時間。

通常,打開DEBUG日誌應該可以幫助調試這樣的問題。