0
votes

I have created inbound and outbound adapters for TCP integration and following is the given configuration.

<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" />

When I run it I message gets send but when response is received at inbound adapter then following exception occurs

no output-channel is available in header.

Then I added one processing element to add that header using header-enricher. After this I am getting

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)

Any help is deeply appreciated.

Thanks, Prashant

1

1 Answers

0
votes

You can't just add gatewayChannel as the reply channel header; the replyChannel header is specific to each message and the gatewayChannel is bridged to it for each message. You are bridging the replyChannel to itself; hence the stack overflow.

You can't use channel adapters here; you must use an outbound gateway instead, so the framework can maintain the replyChannel header.

The tcp-client-server-multiplex sample shows one way of how to achieve a similar result using channel adapters, by saving off the replyChannel and correlating the reply, but it's really much simpler to use a gateway instead.