0
votes

My Requirement is to get data from TCP, after getting the data from TCP convert into java object and send on ActiveMQ. Post that after doing some processing need to send the acknowledgement/response code on same channel on TCP. To fulfill this requirement I am using tcp-outbound-gateway as bidirectional communication is required.

Problem is I am not able to send acknowledgement with ActiveMQ. If I comment out ActiveMQ part and write a dummy string on replyChannel it is visible, but the moment I send the object on Active MQ queue it is giving me a message "null reply received for nothing to send".

I am using a new queue to get the acknowledgement and trying to put the response on reply channel of tcp-outbound-gate, but error message is no output-channel or replyChannel header available.

I got the MessageHeaders details via Incoming message and sending it via queue to use copyHeader. I am able to set the headers and see paylod in Message object, verified the same by applying Interceptos on reply channel, but still getting the same error no output-channel or replyChannel header available.

Code is :

<int:gateway id="gw" default-reply-channel="replyChannel" default-reply-timeout="10000" service-interface= "com.telnet.core.integration.connection.ParseTcpConfiguration$SimpleGateway"
default-request-channel="${server.inboundChannel}"/>

<int:channel id="telnetLandingChannel" />

<ip:tcp-connection-factory id="serverFactory" type="server"  host="${server.host}" port="${server.port}" single-use="false"
serializer="${server.serializer}" deserializer="${server.serializer}" task-executor="serverFactoryTaskExecutor"/>

<ip:tcp-inbound-gateway id="serverInboundAdpater"   request-channel="telnetLandingChannel"  reply-channel="replyChannel"
connection-factory="serverFactory"  error-channel="errorChannel"    reply-timeout="1000000" auto-startup="false"/>    

<int:channel id="replyChannel"></int:channel>

<beans:bean id="acknowledgementHandler"     class= "com.telnet.core.integration.AcknowledgementHandler">
</beans:bean>

<int:channel id="incidentDispatchMessageChannel" datatype="${incident.interaction.dispatch.response.datatype}"></int:channel>

<int-jms:message-driven-channel-adapter id="incidentDispatchMessageChannelAdapter" error-channel="errorChannel"
connection-factory="mqConnectionFactory"
destination-name="${incident.processing.tcp.dispatch.response.queues}" 
channel="incidentDispatchMessageChannel"/>

<int:transformer id="incidentMessageActivator" 
input-channel="incidentDispatchMessageChannel" 
output-channel="replyChannel"
ref="acknowledgementHandler" method="incidentAck">
</int:transformer>    

public Message incidentAck(final DefaultIncidentAcknowledgeMessage defaultIncidentAcknowledgeMessage){

    MessageHeaders ms = (MessageHeaders)defaultIncidentAcknowledgeMessage.getProperties().get("MessageHeader");
    Message<String> message = MessageBuilder.withPayload("1").copyHeaders(ms).build();
    return message;
}
1

1 Answers

0
votes

Need to see your Integration configuration though, but let me guess that you are loosing TemporaryReplyChannel object in the replyChannel header because it isn't Serializable. Consider to use:

<int:header-enricher>
    <int:header-channels-to-string/>
</int:header-enricher>

somewhere before sending to the ActveMQ.

See Reference Manual for more information.

UPDATE

Looks like this is a continuation of Receive the acknowledgement from TCP server to our application using spring Integration. And I see you still use the same replyChannel for many places. That isn't going to work properly. The replyChannel header from the gateway can accept only one reply. Even if we figure out what to do with the reply from ActiveMQ, the TemporaryReplyChannel will be fulfilled with the reply from the TCP Outbound Gateway.

If I understand you correctly, alongside with the reply from the TCP you need also get some message from ActiveMQ. And send everything as a reply to the gateway call. For this purpose I suggest you to consider to use Aggregator and figure out some custom correlation strategy to match the reply from TCP to that acknowledge from the ActiveMQ. After aggregation you really can just use the existing replyChannel header to reply to the gateway.