无法使用spring TCP集成进行路由

时间:2017-06-16 13:20:36

标签: tcp spring-integration

我为TCP集成创建了入站和出站适配器,以下是给定的配置。

<beans:description>
    Uses conversion service and collaborating channel
    adapters.
</beans:description>

<context:property-placeholder />




<!-- Client side -->

<gateway id="gw"
    service-interface="com.project.configuration.ACDGateway"
    default-reply-timeout="20000" default-request-channel="input"
    default-reply-channel="gatewayChannel" />

<ip:tcp-connection-factory id="client" type="client"
    host="10.90.7.31" port="42027" single-use="false"
    serializer="MessageSerializerDeserializerService" deserializer="MessageSerializerDeserializerService"
    so-timeout="10000" />

<publish-subscribe-channel id="input" />

<ip:tcp-outbound-channel-adapter id="outAdapter.client"
    order="1" channel="input" connection-factory="client" /> <!-- Collaborator -->

<beans:bean id="MessageSerializerDeserializerService"
    class="com.project.service.impl.MessageSerializerDeserializerService" />

<ip:tcp-inbound-channel-adapter id="inAdapter.client"
    channel="recieve" connection-factory="client" /> <!-- Collaborator -->
<channel id="recieve" />

<header-enricher input-channel="recieve"
    output-channel="gatewayChannel">
    <header name="replyChannel"
        value="gatewayChannel"/>
</header-enricher>
<channel id="gatewayChannel" />

当我运行它时,消息会被发送,但是当在入站适配器收到响应时,则会发生以下异常

标题中没有输出通道。

然后我添加了一个处理元素,使用header-enricher添加该头。在此之后我得到了

Exception in thread "pool-3-thread-1" java.lang.StackOverflowError
    at org.springframework.beans.factory.support.AbstractBeanFactory.transformedBeanName(AbstractBeanFactory.java:1090)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:239)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:88)
    at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:45)
    at org.springframework.messaging.core.AbstractDestinationResolvingMessagingTemplate.resolveDestination(AbstractDestinationResolvingMessagingTemplate.java:73)
    at org.springframework.messaging.core.AbstractDestinationResolvingMessagingTemplate.send(AbstractDestinationResolvingMessagingTemplate.java:67)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:300)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:212)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:129)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:115)
    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:148)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)
    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.AbstractDestinationResolvingMessagingTemplate.send(AbstractDestinationResolvingMessagingTemplate.java:68)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:300)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:212)
    at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:129)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:115)

非常感谢任何帮助。

谢谢, PRASHANT

1 个答案:

答案 0 :(得分:0)

您不能只添加gatewayChannel作为回复频道标头; replyChannel标头特定于每条消息,并且gatewayChannel为每条消息桥接到它。你正在将replyChannel桥接到自己;因此堆栈溢出。

您不能在此使用频道适配器;您必须使用出站网关,因此框架可以维护replyChannel标头。

tcp-client-server-multiplex sample显示了如何使用通道适配器实现类似结果的一种方法,即保存replyChannel并关联回复,但实际上使用网关要简单得多。