Spring Integration没有响应

时间:2016-03-15 03:51:46

标签: java tomcat spring-integration

我使用Spring Integration来处理服务器和客户端之间的自定义TCP协议。这是我的context.xml:

<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部署它时,它适用于serval分钟,并且它对客户端没有响应。发现一个错误:

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)

我想知道如何解决它以及错误的地方。

1 个答案:

答案 0 :(得分:0)

使用collaborating channel adapters时,必须确保在出站消息中设置ip_connectionId标头,以便适配器知道将其写入哪个套接字。

通常,通过这样的简单流程,框架将负责将标头从入站消息传播到出站消息。

所以我需要看看那种方法,看看你在做什么。

你的'handleMessage`代码是什么样的?

另一种可能性是5秒超时 - 如果您的服务需要的时间超过连接将不再存在。

通常,启用DEBUG日志记录应该有助于调试此类问题。