【问题标题】:Unable to route using spring TCP integration无法使用 Spring TCP 集成进行路由
【发布时间】:2017-06-16 13:20:36
【问题描述】:

我已经为 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)

非常感谢任何帮助。

谢谢, 普拉尚特

【问题讨论】:

    标签: tcp spring-integration


    【解决方案1】:

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

    你不能在这里使用通道适配器;您必须改用出站网关,以便框架可以维护 replyChannel 标头。

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

    【讨论】:

    • 谢谢你,但是当我不添加该标题时,我得到 no output-channel is available in header exception。
    • replyChannel 标头由gw 网关用于关联对请求的回复。您必须从出站消息中保存该标头,当收到回复时,确定它是针对哪个请求并恢复其 replyChannel 标头。正如我所说,如果您使用 tcp 出站网关而不是通道适配器,框架将为您处理所有这些。
    猜你喜欢
    • 1970-01-01
    • 2021-03-11
    • 2018-06-15
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多