I need to create a dynamic TCP outbound adapter that acts as a client, connects to a server, and handles the server’s response. While the request is being sent to the server correctly, I am unable to receive the server’s response. I have verified using Wireshark that the server is indeed sending a response, but my code does not seem to capture it. Please review my code and let me know what might be wrong.
TcpNetClientConnectionFactory cf = new TcpNetClientConnectionFactory(ip, port);
cf.setDeserializer(new CustomDeserializer());
IntegrationFlow out = IntegrationFlow.from("clientInputChannel")
.handle(Tcp.outboundAdapter(cf))
.transform(Transformers.objectToString())
.get();
this.flowContext.registration(out)
.addBean(cf)
.id(port + ".out")
.register();
IntegrationFlow in = IntegrationFlow.from(Tcp.inboundAdapter(cf)).channel("fromTcp").get();
this.flowContext.registration(in)
.id(port + ".in")
.register();
IntegrationFlow responseFlow = IntegrationFlow.from("fromTcp")
.handle(message -> {
log.info("UGV Response " + message.getPayload());
})
.get();
this.flowContext.registration(responseFlow)
.id("errorFlow")
.register();
Following are my Message Channels
@Bean("clientInputChannel")
public MessageChannel clientInputChannel() {
return new DirectChannel();
}
@Bean("fromTcp")
public QueueChannel fromTcp() {
return new QueueChannel();
}
This is how i am send message to server
@Autowired
@Qualifier("clientInputChannel")
private MessageChannel toTcp;
@Override
public boolean sendHex(byte[] buffer) {
log.info("Sending Bytes: " + buffer);
toTcp.send(MessageBuilder.withPayload(buffer).build());
log.info("Bytes Sent");
return true;
}
I have also added ServiceActivator to test but none is working
@ServiceActivator(inputChannel = "fromTcp")
public void receiver(PelcoResponseMessage in) {
System.out.println("Received " + in + " from ");
}
@ServiceActivator(inputChannel = "fromTcp")
public void receiver1(byte[] in) {
System.out.println("Received1 " + in + " from ");
}
@ServiceActivator(inputChannel = "fromTcp")
public void receiver2(String in) {
System.out.println("Received2 " + in + " from ");
}